项目作者: julianocomg

项目描述 :
A simple react-native component to wrap your form fields and get their values with just one single method.
高级语言: JavaScript
项目地址: git://github.com/julianocomg/react-native-form.git
创建时间: 2015-10-15T15:24:21Z
项目社区:https://github.com/julianocomg/react-native-form

开源协议:MIT License

下载


react-native-form

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

Installation

  1. 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

  1. import Form from 'react-native-form'
  2. <Form ref="form">
  3. <View>
  4. <View>
  5. <TextInput type="TextInput" name="myTextInput" ></TextInput> // Yes, it doesn't matter how deep they are :)
  6. </View>
  7. </View>
  8. <Switch type="Switch" name="mySwitch" ></Switch>
  9. <Slider type="Slider" name="mySlider" ></Slider>
  10. <DatePickerIOS type="DatePickerIOS" name="myBirthday" ></DatePickerIOS>
  11. <Picker type="Picker" name="myPicker" ></Picker>
  12. <PickerIOS type="PickerIOS" name="pickers[ios]" ></PickerIOS> // Yes, we support form serialization, like the web
  13. </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:

  1. var customFields = {
  2. 'RadioButtons': {
  3. controlled: true,
  4. valueProp: 'selectedOption',
  5. callbackProp: 'onSelection',
  6. }
  7. }
  8. <Form ref="form" customFields={customFields}>
  9. <RadioButtons type="RadioButtons" name="radioButtons" ></RadioButtons>
  10. </Form>

Support for Accordion

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

  1. type="Accordion"

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

License

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