A simple react-native component to wrap your form fields and get their values with just one single method.

Overview

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.

Comments
  • More elaborate example of using Custom Form components?

    More elaborate example of using Custom Form components?

    What properties are required in the customFields object? I was hoping to use this component to get the value of a custom picker. The picker has a state property called selected which is the value of this picker. How should I go about implementing this functionality?

    opened by peterlazar1993 8
  • Can't get values from custom field in release build

    Can't get values from custom field in release build

    I use this package with TextInput and a custom field RadioButtons from package react-native-radio-buttons.

    Everything works fine in development, I can get all form values with this.refs.form.getValues(). When I build in release, this.refs.form.getValues() is only returns the values of TextInput, nothing from my custom field.

    Really weird behevior, any ideas? Maybe building in release do some optimization that break this feature.

    opened by charpeni 4
  • npm install react-native-form fails for latest react-native pre-release

    npm install react-native-form fails for latest react-native pre-release

    npm ERR! Darwin 14.5.0
    npm ERR! argv "/Users/###/.nvm/versions/node/v5.1.0/bin/node" "/Users/###/.nvm/versions/node/v5.1.0/bin/npm" "install"
    npm ERR! node v5.1.0
    npm ERR! npm  v2.14.12
    npm ERR! code EPEERINVALID
    
    npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
    npm ERR! peerinvalid Peer [email protected] wants [email protected]>=0.11.0
    
    npm ERR! Please include the following file with any support request:
    npm ERR!     /Users/###/Projects/TaskTracker/npm-debug.log
    

    Hello, I'm currently running the latest pre-release of react-native, and while attempting to npm install react-native-form, I get the above error.

    opened by sgarza62 3
  • Question: PickerIOS usage

    Question: PickerIOS usage

    First of all I love this package, great for reducing redundancy in my code.

    I have a quick question about how PickerIOS is implemented with this package, because for some reason the selected value isn't working in my code. Could someone post an example of a functional PickerIOS with this package?

    This is how I tried using it:

    <Form ref="form">
      <PickerIOS name={this.props.name}>
        {
          this.props.options.map(function(option) {
            return (
              <PickerItemIOS
                key={option.id}
                value={option.id}
                label={option.name} />
            );
          })
        }
      </PickerIOS>
    </Form>
    

    Am I missing something? Thanks in advance.

    enhancement question 
    opened by tristangodfrey 3
  • Fix `hasAssign` function to allow uuid keys in objects

    Fix `hasAssign` function to allow uuid keys in objects

    Before this change, when uuid key started with numbers the parseInt returned a truncated value, for example

    $ parseInt('416eae54-cfb0-4245-a812-be8d307f8d1a', 10)

    416

    However, when the key started with an alpha character parseInt returned NaN

    $ parseInt('a8e9a1dc-eda6-4e32-a552-39aa054e069f', 10)

    NaN

    Using a regular expression to check first that all string positions are digits solves the problem.

    opened by dgdavid 2
  • Accordion component support

    Accordion component support

    Added support for Form elements in Accordion components. (This is my first time submitting a pull request. Any feedback or suggestions are appreciated.)

    opened by Proberts 1
  • Feature/check null element

    Feature/check null element

    Adding in a check for element === null since typeof element ends up being object if element is null. This prevents errors in react native if a child node is null within the form wrapper component.

    opened by alex-andreescu 0
  • Putting TouchableWithoutFeedback inside of the form yields an error

    Putting TouchableWithoutFeedback inside of the form yields an error

    <TouchableWithoutFeedback
        onPress={this.showPicker.bind(this, 'min', {
            date: new Date('2000/01/01'),
            maxDate: new Date(),
            minDate: new Date('1900/01/01')
        })}
    >
        <Icon name="event" size={36} />
    </TouchableWithoutFeedback>
    

    This for example throws an error if it's nested in the

    screenshot_20160602-190355

    opened by demiro 0
  • Ability to initialise form with values

    Ability to initialise form with values

    Need a functionality where we can initialize the form inputs with values. This scenario occurs especially in editing any object.

    Something like this, <Form ref='form' customFields={customFields} values={object}>

    opened by rahul100885 0
  • Ability to reset form

    Ability to reset form

    Not sure if this exists or would need to be implemented, but it would be good if a callback was provided to reset to form to initial state, ie. to defaultValue or placeholder.

    opened by b8ne 0
  • Warning: Stateless function components cannot be given refs (See ref

    Warning: Stateless function components cannot be given refs (See ref "REF_NAME" in StatelessComponent created by Form). Attempts to access this ref will fail.

    This error occurs in all form fields that use the function shorthand instead of classes.

    I'm running the latest version of react-native-form. I'm running react-native 0.19. I'm assuming that this is an issue with my version of RN, but it'd be awesome if this library supported it.

    opened by PaulBGD 1
Simple form validation library for React Native.

Foect Simple form validation library for React Native. Installing Npm npm i --save foect Yarn yarn add foect Quick Start import { TextInput, Text, V

null 38 Nov 11, 2022
📝 Form component for React Native.

Gifted Form Form component for React Native. Example var { GiftedForm, GiftedFormManager } = require('react-native-gifted-form'); var FormComponent =

Farid Safi 1.4k Dec 19, 2022
Easy react-native forms using bootstrap-like syntax with redux-form+immutablejs integration. Styled using styled-components

react-native-clean-form Easy react-native forms using bootstrap-like syntax with redux-form+immutablejs integration. Styled using styled-components Bi

Esben Petersen 475 Oct 30, 2022
A Formik inspired form library that uses MobX under the hood

Formix A Formik inspired form library that uses MobX under the hood and update only the changed fields. Installation Using npm: npm install @euk-labs/

Shoulders 6 Dec 29, 2021
A simple, declarative API for creating cross-platform, native-appearing forms with React Native

React Native Forms Project status I wrote this library several (many?) years ago for a use-case at work, when React Native was still quite young, comp

Michael Helvey 87 Jul 10, 2022
A simple validation library for react native

react-native-form-validator A simple validation library for react native Installation Run: $ npm i react-native-validation --save Validators: matchReg

Şerafettin Aytekin 14 Mar 25, 2021
Handle your forms in a smart way

react-native-form-builder Note: If you're looking for a better form management library with more advanced features, Please check out React Reactive Fo

Kuldeep Saxena 117 Jul 24, 2022
React component for convert the valle screens-api data structure to web component based forms.

valleForm React component for convert the valle screens-api data structure to web component based forms. Write <valleForm tabs = { [...] } but

Valle Sistemas de Gestão 7 Dec 16, 2021
Generate forms with native look and feel in a breeze

React Native Form Generator Generate forms with native look and feel in a breeze Components Picker DatePicker TimePicker Input Link Separator Switch F

Michael Cereda 375 Dec 7, 2022
📋 React Hooks for forms validation (Web + React Native)

Version 7 | Version 6 English | 日本語 Features Built with performance, UX and DX in mind Embraces native form validation Out of the box integration with

React Hook Form 32.6k Jan 8, 2023
Forms library for react-native

Notice tcomb-form-native is looking for maintainers. If you're interested in helping, a great way to get started would just be to start weighing-in on

Giulio Canti 3.2k Dec 17, 2022
Project using React Router, Styled Components, useEffect, useState and context

Before run do the steps bellow install npm or yarn To run this application you can just use npm or if you want, yarn is another option. Download NPM I

Guilherme Mello 0 Dec 29, 2021
Build forms in React, without the tears 😭

Build forms in React, without the tears. Visit https://formik.org to get started with Formik. Organizations and projects using Formik List of organiza

Formium 31.7k Dec 31, 2022
Angular like reactive forms in React.

React Reactive Forms It's a library inspired by the Angular's Reactive Forms, which allows to create a tree of form control objects in the component c

Kuldeep Saxena 290 Nov 26, 2022
Next-generation react form fields built on top of jotai form primitives.

Atomic Form Fields for React Declarative & headless form fields build on top of jotai & form-atoms. yarn add jotai form-atoms @form-atoms/field Motiv

null 6 Feb 13, 2023
Hooks that wrap unstable values for more control over incoming hook dependencies

Hooks that wrap unstable values for more control over incoming hook dependencies

Rico Kahler 6 Sep 28, 2022
A javascript microframework to shorten daily use CSS class manipulator methods by adding them all into a single method

CSS Class Builder A small typescript package built to work with ReactJS to short

Ankit Mishra 2 Jan 7, 2022
Keep-react-hook-form - A lib to store react-hook-form values in session storage

Keep-react-hook-form - A lib to store react-hook-form values in session storage

Christopher 1 Jan 27, 2022
React component used for selecting multiple values or single states from several options

react-selectlist React component used for selecting multiple values or single statess from several options Install npm i --save react-selectlist Demo

CT Hung 2 Apr 6, 2021