All Projects → nicolaslopezj → Simple React Form

nicolaslopezj / Simple React Form

Licence: mit
The simplest way to handle forms in React

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Simple React Form

Meteor Client Bundler
https://blog.meteor.com/leverage-the-power-of-meteor-with-any-client-side-framework-bfb909141008
Stars: ✭ 187 (-16.52%)
Mutual labels:  meteor
Rich Model Forms Bundle
Provides additional data mappers that ease the use of the Symfony Form component with rich models.
Stars: ✭ 198 (-11.61%)
Mutual labels:  form
Ant Plus
🔺 Ant Design 表单简化版
Stars: ✭ 212 (-5.36%)
Mutual labels:  form
Epage
一款基于schema的可视化页面配置工具
Stars: ✭ 194 (-13.39%)
Mutual labels:  form
Pristine
Vanilla javascript form validation micro-library
Stars: ✭ 197 (-12.05%)
Mutual labels:  form
Material Singleinputform
A single EditText instead of a classical form. Library that implements flavienlaurent's singleinputform
Stars: ✭ 202 (-9.82%)
Mutual labels:  form
Registry
Schema Registry
Stars: ✭ 184 (-17.86%)
Mutual labels:  schemas
Angular Surveys
Angular survey / form builder inspired by Google Forms
Stars: ✭ 219 (-2.23%)
Mutual labels:  form
Meteor Google Maps
🗺 Meteor package for the Google Maps Javascript API v3
Stars: ✭ 198 (-11.61%)
Mutual labels:  meteor
Analytics
UNMAINTAINED! - Complete Google Analytics, Mixpanel, KISSmetrics (and more) integration for Meteor
Stars: ✭ 211 (-5.8%)
Mutual labels:  meteor
Stevejobs
A simple jobs queue that just works (for Meteor.js)
Stars: ✭ 195 (-12.95%)
Mutual labels:  meteor
Form
The Form component allows you to easily create, process and reuse HTML forms.
Stars: ✭ 2,406 (+974.11%)
Mutual labels:  form
Floatl
☁️ A pragmatic implementation of the Float Label Pattern for the web
Stars: ✭ 204 (-8.93%)
Mutual labels:  form
Elm Form
Dynamic forms handling in Elm
Stars: ✭ 189 (-15.62%)
Mutual labels:  form
Kirby Uniform
A versatile Kirby plugin to handle web form actions.
Stars: ✭ 214 (-4.46%)
Mutual labels:  form
Redux Form
A Higher Order Component using react-redux to keep form state in a Redux store
Stars: ✭ 12,597 (+5523.66%)
Mutual labels:  form
Django Material
Material Design for Django
Stars: ✭ 2,362 (+954.46%)
Mutual labels:  form
Vue Dynamic Form Component
Vue dynamic nested form component, support nested Object/Hashmap/Array. Vue动态多级表单组件,支持嵌套对象/Hashmap/数组。
Stars: ✭ 220 (-1.79%)
Mutual labels:  form
Angular Meteor
Angular and Meteor - The perfect stack
Stars: ✭ 2,385 (+964.73%)
Mutual labels:  meteor
Heyui
🎉UI Toolkit for Web, Vue2.0 http://www.heyui.top
Stars: ✭ 2,373 (+959.38%)
Mutual labels:  form

Simple React Form

travis-ci npm version

Simple React Form is the simplest way to handle forms in React. It helps you make reusable form components in React and React Native.

This is just a framework, you must create the form components or install a package with fields that you will use.

To use with react native check here

Installation

Install the base package

npm install --save simple-react-form

Example

import React from 'react'
import {Form, Field} from 'simple-react-form'
import DatePicker from './myFields/DatePicker'
import Text from './myFields/Text'

class PostsCreate extends React.Component {
  state = {}

  render() {
    return (
      <div>
        <Form state={this.state} onChange={state => this.setState(state)}>
          <Field fieldName="name" label="Name" type={Text} />
          <Field fieldName="date" label="A Date" type={DatePicker} />
        </Form>
        <p>My name is {this.state.name}</p>
      </div>
    )
  }
}

Contributions

Docs

Using with state

In this example, the current value of the form will be stored in this.state

import React from 'react'
import {Form, Field} from 'simple-react-form'
import DatePicker from './myFields/DatePicker'
import Text from './myFields/Text'

class PostsCreate extends React.Component {
  state = {}

  render() {
    return (
      <div>
        <Form state={this.state} onChange={state => this.setState(state)}>
          <Field fieldName="name" label="Name" type={Text} />
          <Field fieldName="date" label="A Date" type={DatePicker} />
        </Form>
        <p>My name is {this.state.name}</p>
      </div>
    )
  }
}

Using without state

In this example, the current value of the form will be stored inside the Form component and passed in the onSubmit function. The difference on this is that the state prop does not change over time.

import React from 'react'
import {Form, Field} from 'simple-react-form'
import DatePicker from './myFields/DatePicker'
import Text from './myFields/Text'

class PostsCreate extends React.Component {
  state = {}

  onSubmit({name, date}) {}

  render() {
    return (
      <div>
        <Form ref="form" state={this.props.initialDoc} onSubmit={this.onSubmit}>
          <Field fieldName="name" label="Name" type={Text} />
          <Field fieldName="date" label="A Date" type={DatePicker} />
        </Form>
        <button onClick={() => this.refs.form.submit()}>Submit</button>
      </div>
    )
  }
}

Field Types

React Simple Form is built from the idea that you can create custom components easily.

Basically this consist in a component that have the prop value and the prop onChange. You must render the value and call onChange passing the new value when the value has changed.

import UploadImage from '../components/my-fields/upload'

<Field fieldName='picture' type={UploadImage} squareOnly={true}/>

Creating the field type

You must create a React component.

import React from 'react'

export default class UploadImage extends React.Component {
  render() {
    return (
      <div>
        <p>{this.props.label}</p>
        <div>
          <img src={this.props.value} />
        </div>
        <TextField
          value={this.props.value}
          hintText="Image Url"
          onChange={event => this.props.onChange(event.target.value)}
        />
        <p>{this.props.errorMessage}</p>
      </div>
    )
  }
}

You can view the full list of props here.

React Native

With React Native the api is the same, but you must enclose the inner content of the form with a View component.

Example:

import React from 'react'
import {View, TextInput} from 'react-native'

export default class TextFieldComponent extends React.Component {
  render() {
    return (
      <View>
        <TextInput
          style={{height: 40, borderColor: 'gray', borderWidth: 1}}
          onChangeText={this.props.onChange}
          value={this.props.value}
        />
      </View>
    )
  }
}

Render the form in the component you want

import Text from '../components/my-fields/text'

<Form state={this.state} onChange={changes => this.setState(changes)}>
  <View>
    <Field fieldName='email' type={Text}/>
    <Field fieldName='password' type={Text}/>
  </View>
</Form>

You should always render your fields inside a View when using react native.

WithValue High order component

If you need to get the current value of the form in the children you can use the WithValue component

import React from 'react'
import {Form, Field, WithValue} from 'simple-react-form'

export default class Example extends React.Component {
  render() {
    return (
      <div>
        <Form>
          <WithValue>
            {value => (
              <div>
                <p>The name is {value.name}</p>
                <Field fieldName="name" label="Name" type={Text} />
              </div>
            )}
          </WithValue>
        </Form>
      </div>
    )
  }
}

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].