vdux-input
Input component with error handling
Last updated 5 years ago by ashaffer88 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install vdux-input 
SYNC missed versions from official npm registry.

input

js-standard-style

Stateful input component with error handling based on the stateless Input component in vdux-ui.

Installation

$ npm install vdux-input

Usage

All the props are the same as for <Input/>. The only difference is that this component holds a little bit of state around error messages so that it works with Form. You can use it like this:

function render () {
  return (
    <Form onSubmit={createUser} validate={validateUser}>
      <Input name='username' />
    </Form>
  )
}

function validateUser (user) {
  if (!user.username || user.username.length <= 3) {
    return {
      valid: false,
      errors: [
        {
          field: 'username',
          message: 'Username must be at least 3 characters'
        }
      ]
    }
  }

  return {
    valid: true
  }
}

Validation functions

If you want an easy, simple way to create reusable schemas that generate errors in this form, check out:

  • schema - Clean, fluent API for creating schemas
  • validate - Takes a schema and returns a validate(model) function that returns errors in the format used here.

API - props

The props API is the same as vdux-ui/input. Refer to that for props documentation.

License

MIT

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

1 Versions

  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (11)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |