react-native-form
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/react-native-form package

2.1.3 • Public • Published

react-native-form

A simple react-native component to wrap your form fields and get their values without attaching listeners everywhere.

Installation

npm install --save react-native-form

Usage

Just put your fields inside the form, with 2 props:

name => Your key to retrieve the value (required)

type => The field type (required)

key => Required for fields with the same name

import Form from 'react-native-form'
 
<Form ref="form">
  <View>
    <View>
      <TextInput type="TextInput" name="myTextInput" /> // Yes, it doesn't matter how deep they are :)
    </View>
  </View>
  
  <Switch type="Switch" name="mySwitch" />
  <Slider type="Slider" name="mySlider" />
  <DatePickerIOS type="DatePickerIOS" name="myBirthday" />
  <Picker type="Picker" name="myPicker" />
  
  <PickerIOS type="PickerIOS" name="pickers[ios]" /> // Yes, we support form serialization, like the web
</Form>

And then you can call ***this.refs.form.getValues()***. You will get an object with all the values serialized. Simple as that.

Do you want to use custom fields?

Just pass the prop customFields to the form. Check out the example below using the react-native-radio-buttons field:

var customFields = {
  'RadioButtons': {
    controlled: true,
    valueProp: 'selectedOption',
    callbackProp: 'onSelection',
  }
}
 
<Form ref="form" customFields={customFields}>
  <RadioButtons type="RadioButtons" name="radioButtons" />
</Form>

Support for Accordion

If you have form fields under an Accordion component, add:

type="Accordion"

to the Accordion component to have Form include the Accordion children.

License

react-native-form is licensed under the MIT license.

Package Sidebar

Install

npm i react-native-form

Weekly Downloads

213

Version

2.1.3

License

MIT

Unpacked Size

11.8 kB

Total Files

5

Last publish

Collaborators

  • julianocomg