Git Product home page Git Product logo

react-forms's Introduction

React Forms

Travis build status Coverage

React Forms library provides a set of tools for React to handle form rendering and validation.

Table of Contents

Installation

To use version documented here you need to install beta tag from npm:

% npm install react-forms@beta

You would probably also need a module bundler such as Browserify or Webpack as React Forms is distributed as a set of CommonJS modules.

Usage

React Forms doesn't provide any <Form /> component, instead it makes implementing form components an easy task.

Note that examples are written using ES2015 syntax. You would probably use Babel with es2015 and react presets enabled to compile code to ES5 which is compatible with most of the current runtimes.

Basic form component.

This is the example where form value is managed as a part of local component state. Some might put form value in a Flux/Redux store instead.

import React from 'react'
import {Fieldset, Field, createValue} from 'react-forms'

class Form extends React.Component {

  constructor(props) {
    super(props)
    let formValue = createValue({
      value: props.value,
      onChange: this.onChange.bind(this)
    })
    this.state = {formValue}
  }

  onChange(formValue) {
    this.setState({formValue})
  }

  render() {
    return (
      <Fieldset formValue={this.state.formValue}>
        <Field select="firstName" label="First name" />
        <Field select="lastName" label="Last name" />
      </Fieldset>
    )
  }
}

Then you can use <Form /> component like any regular React component:

import {render} from 'react-dom'

render(
  <Form value={{firstName: 'Michael', lastName: 'Jackson'}} />,
  document.getElementById('form')
)

Validation

React Forms can validate form value using JSON schema:

let schema = {
  type: 'object',
  properties: {
    firstName: {type: 'string'},
    lastName: {type: 'string'}
  }
}

Simply pass it to a createValue(..) function:

let formValue = createValue({value, onChange, schema})

API Reference

<Field />

<Fieldset />

createValue({schema, value, onChange})

WithFormValue(Component)

Howto Guides

Customizing form fields

All components in React Forms conform to React Stylesheet API. That means that for injecting customization one needs react-stylesheet package to be installed:

% npm install react-stylesheet

Customizing label rendering:

import React from 'react'
import {style} from 'react-stylesheet'
import {Field as BaseField, Label as BaseLabel} from 'react-forms'

function Label({label, schema}) {
  return <BaseLabel className="my-label" label={label} schema={schema} />
}

let Field = style(BaseField, {
  Label: Label
})

Customizing error list rendering:

import React from 'react'
import {style} from 'react-stylesheet'
import {Field as BaseField, ErrorList as BaseErrorList} from 'react-forms'

function ErrorList({formValue}) {
  return <BaseErrorList className="my-error-list" formValue={formValue} />
}

let Field = style(BaseField, {
  ErrorList: ErrorList
})

Form field with custom input component:

import React from 'react'
import {Field} from 'react-forms'
import Datepicker from 'datepicker'

function DateField(props) {
  return <Field {...props} Input={Datepicker} />
}

Implementing form field component from scratch:

import React from 'react'
import {WithFormValue} from 'react-forms'

class Field extends React.Component {

  render() {
    let {formValue} = this.props
    return (
      <div>
        <label>{formValue.schema.label}</label>
        <input value={formValue.value} onChange={this.onChange} />
      </div>
    )
  }

  onChange = (e) => this.props.formValue.update(e.target.value)
}

Field = WithFormValue(Field);

Pattern for reusable forms

import React from 'react'
import {Fieldset} from 'react-forms'

class IndividualFieldset extends React.Component {

  static schema = {
    type: 'object',
    properties: {
      firstName: {type: 'string'},
      lastName: {type: 'string'}
    }
  }

  static value = {
    firstName: 'John',
    lastName: 'Doe'
  }

  render() {
    let {label, ...props} = this.props
    return (
      <Fieldset {...props}>
        <label>{label}</label>
        <Field
          select="firstName"
          label="First name"
          />
        <Field
          select="lastName"
          label="Last name"
          />
      </Fieldset>
    )
  }
}

Later you can compose schema and initial form value using IndividualFieldset.schema and IndividualFieldset.value static properties and use <IndividualFieldset /> component itself for rendering.

let schema = {
  type: 'object',
  properties: {
    mother: IndividualFieldset.schema,
    father: IndividualFieldset.schema
  }
}

let value = {
  mother: IndividualFieldset.value,
  father: IndividualFieldset.value
}

class FamilyForm extends React.Component {

  constructor(props) {
    super(props)
    this.state = {formValue: createValue({schema, value, this.onChange})}
  }

  onChange = (nextFormValue) => {
    this.setState({formValue: nextFormValue})
  }

  render() {
    return (
      <Fieldset formValue={this.state.formValue}>
        <IndividualFieldset
          select="mother"
          label="Mother"
          />
        <IndividualFieldset
          select="father"
          label="Father"
          />
      </Fieldset>
    )
  }
}

Examples

Examples are located at examples folder. To run.

cd examples
npm install
npm start

open http://localhost:4000 in browser

Credits

React Forms is free software created by Prometheus Research, LLC and is released under the MIT license.

react-forms's People

Contributors

adamroyle avatar andreypopp avatar davidkpiano avatar maslianok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-forms's Issues

Add support for disabled (and possibly read-only) nodes

Given that it's possible for a schema to be updated dynamically (a feature I'm using heavily), it feels like having disabled nodes in the schema should be possible. This would be similar usage to the required attribute. If a node is disabled its data should be excluded from the data object, (vanilla form submission would be fine because the disabled attribute does all the work), any sub-mappings should also inherit the disabled behaviour from their parent. And obviously disabling a field would also bypass its validation.

Related: A similar readonly attribute could also exist which works in more-or-less the same way, but renders out a string rather than a disabled input. I don't have a strong use case for this yet, but I would imagine it being used in situations where a user's permission changes some aspect of the schema, but you don't also want to change the layout component you may have defined.

Don't publish JSX to npm?

I'm a little confused about the distribution of this package (and the react-forms-build repo). Code published to npm shouldn't require a build to be used. The convention with compile-to-JS languages is to put the raw code in src/ and then compile to lib/ on prepublish. .npmignore can be used to prevent the src/ directory from being published at all (if you want) and .gitignore can be used to prevent pushing the lib/ directory to GitHub.

The harmony stuff is a little murkier since node has the --harmony flag, but it seems like the features you're using could be compiled to es5 without any harm too.

Not only would this simplify the process of getting started with the library, it would also be more in line with how npm is used (and meant to be used).

FormFor/FormElementMixin throws unhelpful error when provided with invalid 'name' prop

Specifying a 'name' prop of FormFor/FormElementMixin is useful for creating a form element representing some single property or subtree in a schema.
However if the provided 'name' doesn't exist in the schema, the error thrown is a generic 'invalid schema node' invariant error. Debugging this requires digging into react-forms implementation to see that the Value#get calls Value#schema.get(name) which returns nothing.

Not sure what the preferred error handling approach is here, but considering 'FormFor' is part of the main API, providing a name which doesn't exist in the schema should throw an error to that effect (ideally, including the name for which a schema is not found).

RadioButtonGroup firing overall form's onChange handler

I'm using the supplied RadioButtonGroup (and also my own version of it that uses a select box instead), when the value changes, the form's onChange handler is triggered with the synthentic event as the only argument, despite the schema itself not being valid. This doesn't happen with the default input

Hide/show individual fields

Hey @andreypopp, just wanted to drop a quick note to say great job on this project. I'd been working on something similar, and I'm happy to see that structurally things are fairly similar to what I'd been doing.

I'll definitely be looking to seeing if there's anything I can contribute back.

Quick question though, one of the things which had been difficult about what I'd been working on, was the ability to hide and show individual fields or fieldsets based on state changes in the form... e.g. if you changed a dropdown to one option, it might show a set of fields, whereas if you changed the dropdown to something else, an entirely different set of fields would be displayed.

I was wondering whether this behavior is currently supported (didn't see it in the docs), or if there'd be a good place to look in the code if were possible, just undocumented.

React reference undefined in AMD environment

I'm getting an error when I try to use this library in an AMD environment. It can't find the React variable. In the code I see this:

//...
})(window, function(React) {
  return __browserify__('./lib/');
});

So... even though we're generating a dependency injection for React (which does successfully resolve), it's not actually being used by the browserify'd code.

Then several times in the code there is:

var React       = (window.React);

So... regardless of AMD presence we are still looking for a global variable.

The way it works is not a deal breaker, but if it's too much trouble to fix we should probably at least document that React must be exposed as a global.

lower-case problem

ReactifyError: /Users/Jeff/repos/ghtemp/node_modules/react-forms/lib/Form.js: Lower case component names (component) are no longer supported in JSX: See http://fb.me/react-jsx-lower-case while parsing file: /Users/Jeff/repos/ghtemp/node_modules/react-forms/lib/Form.js

Animating conditionally rendered fields

I'm trying to animate fields that are conditionally rendered based on another fields value. I'm trying to use CSSTransitionGroup addon to give me some css class hooks.

var FormFor = ReactForms.FormFor;
var Animate = React.addons.CSSTransitionGroup;

var SpecialFieldset = React.createClass({
  mixins: [ReactForms.FieldsetMixin],

  render: function() {
    return (
      <div>
        <FormFor name="name" />
        <FormFor name="anotherField" />
        {this.valueLens().val().age > 18 &&
          <Animate transitionName="FadeIn">
            <FormFor name="specialField" />
          </Animate>
        }
      </div>
    )
  }
})

My example is similar to the fieldset customisation example. It works in the sense that the field is rendered but the animation never happens.

Is this possible, if so what am I missing?

Add concept of a Layout node (or similar), like a Mapping but adding no semantics

I have some forms where it doesn't make sense for me to create deep nestings of Mappings, when the actual data for the form is relatively flat. At the moment I'm using Mappings primarily to group fields together for presentational, rather than functional reasons, which means I'm doing extra work to transform data from the mostly flat format my application uses, to the format that react-forms uses.

It would be useful to be able to have field groupings that don't actual alter the data schema. I don't know what the API could be, since the new key-value approach to schema definition means that it's not really possible to have a node that doesn't have a name (at the moment I'm giving them dumb names like 'group1', 'group2' etc).

Alternatively, it might be worth investigating some patterns for defining the layout of a form independently of the data definition.

I've attached a screenshot of the form I'm trying to define.

screen shot 2014-12-02 at 15 58 59

Add README for running local docs site

This would be useful for contributing docs changes.

These are the steps i took to get the docs running locally for me:

$ cd react-forms
$ npm install
$ npm link
$ cd docs
$ npm install
$ npm link react-forms
$ ./node_modules/.bin/wintersmith preview

For some reason the makefile didn't seem to be adding the node_modules/.bin folder to my path so was failing.

Thanks for the cool project!

Syntax error when require react-forms

Hey People,

I try to incorporate the getting started example into my project.
But then I get this syntax error.

node_modules/react-forms/lib/index.js:30
FormMixin, FormContextMixin, FormElementMixin,
^
SyntaxError: Unexpected token ,
at Module._compile (module.js:439:25)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (/home/djan/dev/react-quickstart/pages/main.js:8:18)
at Module._compile (module.js:456:26)
at Object.require.extensions.(anonymous function) as .js
at Module.load (module.js:356:32)
Program node server.js exited with code 8

Starting child process with 'node server.js'

Here my code:

  var React       = require('react');                                      
var Schema = ReactForms.schema.Schema;                                   
var Property = ReactForms.schema.Property;                               
var Form = ReactForms.Form;   

  var schema = (                                                           
    <Schema>                                                               
    . <Property name="firstName" />                                        
    . <Property name="lastName" />                                         
    . <Property name="age" type="number" />                                
    </Schema>                                                              
  );                                                                       

  var MainPage = React.createClass({                                       

    render: function() {                                                       
    . return (                                                             
    . . <div className="container">                                        
    . . . <div className="col-md-9 home">                                      
. . . . <div className="navbar navbar-default">                        
    . . . . . <div className="navbar-header">                              
    . . . . . . <a href="/" className="navbar-brand"></a>                  
    . . . . . </div>                                                       
    . . . . </div>                                                         
    . . . . <h1>Hello, anonymous!</h1>                                     
    . . . . . <ul className="nav nav-pills">                               
    . . . . . . <li className="active"><a href="/">Home</a></li>           
    . . . . . . <li><a href="/tasks">Todo List</a></li>                    
    . . . . . . <li><a href="/register">Register</a></li>                  
    . . . . . </ul>                                                        
    . . . . . <Form schema={schema} />                                     
    . . . </div>                                                           
    . . </div>                                                             
    . );    

To be complete, here is also my package.json.

{                                                                          
  name: react-quickstart,                                                  
  version: 0.0.0,                                                          
  description: React project,                                              
  main: ./server.js,                                                       
  browser: ./client.js,                                                    
  browserify: {                                                            
  . transform: [                                                           
  . . [reactify, {harmony: true}]                                          
  . ]                                                                      
  },                                                                       
  dependencies: {                                                          
  . react: 0.11.0,                                                         
  . react-forms:0.6.3,                                                     
  . react-async: 1.0.2,                                                    
  . react-router-component: 0.22.0,                                        
  . react-bootstrap:0.12.0,                                                
  . node-jsx: ~0.10.0,                                                     
  . express: ~4.9.0,                                                       
  . body-parser:1.9.1,                                                     
  . less-middleware: 1.0.4,                                                  . errorhandler: 1.1.1,                                                   
  . connect-flash:0.1.1,                                                   
  . passport:0.2.1,                                                        
  . superagent: ~0.18.0,                                                   
  . fibers: ~1.0.1                                                         
  },                         
devDependencies: {                                                       
  . reactify: ~0.13.1,                                                     
  . envify: ~1.2.0,                                                          . browserify: ~3.44.2,                                                   
  . connect-browserify: ~2.0.1,                                            
  . uglify-js: ~2.4.13,                                                    
  . supervisor: ~0.6.0                                                     
  },                                                                       
  scripts: {                                                               
  . test: echo \"Error: no test specified\" && exit 1,                     
  . start: supervisor -i node_modules -e js,jsx server.js,                 
  . build: NODE_ENV=production browserify ./ | uglifyjs -cm 2>/dev/null    > ./assets/bundle.js,                                                      
  . start-prod: NODE_ENV=production node server.js,                        
  . clean: rm -f ./assets/bundle.js                                        
  },                                                                       
  author: "",                                                              
  license: MIT                                                             
}

Can you help me? I do not see what's wrong.

Best regards
Jan

Allow styling concrete form components

Three options:

  • either we add to each component a CSS class of the form rf-FormElement[fieldset.fieldname]
  • or we allow setting an additional CSS class via schema prop: <Property componentClassName="some-class" />
  • or we allow passing configured component instances to schema's component prop and so one can do <Property component={<Field className="some-class" />} />. That also makes API more consistent with how we treat input components.

Add class to `.react-forms-field` when field is focused?

We have a design that incorporates the label and input in a single box.

screen shot 2014-05-08 at 2 29 01 pm

When the input is focused, we want to highlight the entire box.

screen shot 2014-05-08 at 2 29 08 pm

To do this, we think we need to add onFocus and onBlur event handlers to the input that changes some state in the Field that is referenced in the classSet. Do you think this would be a good addition to react-forms?

Unable to use react-forms

I'm not sure this issue belongs specifically in this repository - the problem appears in libraries that are dependencies, but that modifying package.json seems to at least partially resolve the issue I'm hoping its right.

I've tried to install this library and use it, but as soon as it is included, I get the following error from browserify:

โžœ  formerror  node_modules/.bin/browserify -o bundle.js -d .

/Users/tim/Sites/formerror/node_modules/browserify/node_modules/module-deps/node_modules/resolve/lib/async.js:29
    if (x.match(/^(?:\.\.?\/|\/|([A-Za-z]:)?\\)/)) {
          ^
TypeError: Object reactify,[object Object] has no method 'match'
    at resolve (/Users/tim/Sites/formerror/node_modules/browserify/node_modules/module-deps/node_modules/resolve/lib/async.js:29:11)
    at makeTransform (/Users/tim/Sites/formerror/node_modules/browserify/node_modules/module-deps/index.js:221:9)
    at ap (/Users/tim/Sites/formerror/node_modules/browserify/node_modules/module-deps/index.js:148:13)
    at applyTransforms (/Users/tim/Sites/formerror/node_modules/browserify/node_modules/module-deps/index.js:158:11)
    at /Users/tim/Sites/formerror/node_modules/browserify/node_modules/module-deps/index.js:121:17
    at fs.js:271:14
    at Object.oncomplete (fs.js:107:15)

My package.json:

{
  "name": "formerror",
  "version": "0.0.1",
  "description": "formerror.",
  "main": "app.js",
  "dependencies": {
    "react": "~0.11.0",
    "react-forms": "^0.6.1"
  },
  "devDependencies": {
    "browserify": "~2.36.0",
    "envify": "~1.2.0",
    "reactify": "~0.4.0",
    "watchify": "~0.4.1"
  },
  "scripts": {
    "start": "STATIC_ROOT=./static watchify -o js/bundle.js -r react -v -d ."
  },
  "browserify": {
    "transform": [
      "reactify",
      "envify"
    ]
  }
}

My app.js:

/** @jsx React.DOM */

var react = require('react');
var ReactForms = require('react-forms');

I've traced the error back to module-deps of browserify, it is receiving [ 'reactify', { es6:true } ] when it expects a string. Removing the browserify transforms from react-forms' package.json works, except it loses its es6 transforms and hence wont parse.

Is my configuration wrong? I've been over the quick start for react-forms a few times and I cant see anything specific to transforms that I need to set up or worry about. :(

Any help would be appreciated, even just a pointer where I need to go to to look.

Each child of <Schema> node should have name property

Hey,

I'm trying to create the following:

var customProperty = React.createClass({
    render: function() {
        <Property name={this.props.name} label="Default Label" validation={this.valid()}/>
    },

    valid: function(value) {
        return true;
    }
});

The code does not perform anything fancy, I'm just trying to compose my custom property with the one from React Forms in order to do the following:

var customSchema = (
    <Schema>
        <CustomProperty name="Property"/>
    </Schema>
)

But when showed in the browser an invariant is triggered saying "Each child of node should have name property", is that correct? How can I create a custom generic property to be extended for common functionality?
Thanks

Should not use the keyword "for" as a function name

According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Reserved_Words "for" is a keyword and should not be used as a variable or function name.

Unfortunately in IE8 this causes a parse error "Expected identifier" which as part of a bundled javascript file causes the rest of the application to crash.

It's probably best to just rename it (currently defined in lens.js) but alternatively you could access the function using bracket notation.

Examples are lacking

So I see the potential in this and want to use it but to even get a basic example up and running seems pretty difficult.

var MyForm = React.createClass({
  mixins: [ReactForms.FormMixin],

  handleSubmit(e) {
    e.preventDefault();
    if(ReactForms.validation.isFailure(this.value().validation)) {
      console.log('invalid form');
      return;
    }

    // form is valid submit to end point
  },

  render() {
    return (
      this.transferPropsTo(
        <form onSubmit={this.handleSubmit}>
          <FormFor />
          <input type='submit' />
        </form>
      )
    );
  }
});

So this is my base form component that all forms will start from. I then render a form as follows:

var schema = (
  <Schema>
    <Property
      name='description'
      label='Message'
      input={<textarea placeholder='Give us details here...' />}
    />
    <Property
      name='email'
      label='Email'
      input={<input type="email" />}
      validate={function(v) {
        return reEmail.test(v);
      }}
    />
  </Schema>
);

return (
  <MyForm schema={schema}  />
);

Now I'm confused as to how I make fields required? In my onSubmit the form will fail if they try and submit an empty form.

I feel like it would be good to have some more examples on simpler stuff as the docs seem a bit confusing.

Show Inline Errors on form Submit

I like how the default behavior is to show inline validation. If we could trigger this on all the fields when the form is submitted, that would make the default user experience nicer.

In the meantime, how can I do this manually? I'd like to just say something like:

onSubmit: function() {
    //...

    this.refs.form.fields.forEach(function(field){
        field.notify()
    });

    //...
}

I haven't been able to figure out how to do this from documentation or reading the code.

updateValue not rendering change

I have a form that I want to reset when a cancel button is pressed. I've got a reset function in my react class that calls:
this.refs.customform.refs.form.updateValue([null]);
If I log out the value for the form I can see that it's being changed internally but the changes are not being rendered to the screen.
I've also tried changing the value().value directly and passing in an object of the forms values to updateValue and get the same issue.

Release 0.7.0 ?

Hi, I need the fixes in 0.7.0, when it will be released ?

onBlur on Property tag

I have coded my property field like this.

clickHandler is a global function.

<Property input={} name='id' label='Username' defaultValue={props.id} required />

Here my onBlur handler never gets fired.

Clues ??

Built-in validation messages do not work with i18n

We are building an app that uses i18n. Unfortunately, the default messages like 'value is required' and 'at least one value is required' are hard-coded in English and there doesn't appear to be any way to configure this.

BEM syntax for classes?

At Causes we have been starting to use BEM (Block, Element, Modifier) methodology for our classes. It looks roughly like:

.block {}
.block__element {}
.block--modifier {}

While the syntax felt a bit aesthetically unpleasant at first, we have actually found it to be a valuable way to name our classes that improves readability and performance (due to shorter selector chains), communicates the structure more clearly, and reduces the likelihood of naming collisions. Over time, we have discovered that this makes working with our styles a good amount easier.

We think this methodology might be useful for react-forms and are wondering what you think. A quick glance at some of the classes you are using written as BEM would look like:

  • react-forms-field becomes react-forms__field
  • invalid (or react-forms-invalid?) becomes react-forms__field--invalid
  • react-forms-hint becomes react-forms__hint
  • react-forms-message becomes react-forms__message
  • react-forms-fieldset becomes react-forms__fieldset
  • react-forms-repeating-fieldset becomes react-forms__repeating-fieldset (or react-forms__fieldset--repeating?)

What do you think about this?

Add support for name attribute on form elements.

I'm not sure how you'd make this work with list and mapping nodes, but for the simple use cases it would be good to be able to submit the form directly without going through the API. For sub-mappings I'd probably go with prefixing based on the parent's name, and double-underscore seperation ie {parent}__{scalar-name}. For lists i'd use {parent}__{array-index}__{scalar-name}. This might be a good starting point for now, since it's better than the current behaviour of not having names, but a further enhancement would be to allow a node to take a function that defines the naming scheme.

Forms don't re-render if the schema changes

I have a parent component that listens for external events and changes it's state if necessary, its render method includes fetching the schema (by calling a function, allowing the schema to change depending on state) and rendering the form using the

component. Despite the schema changing, the re-rendering Form doesn't update to reflect the new schema.

My primary use case is updating the choices for select boxes (or similar).

Here's a simplified version of what I'm doing: https://gist.github.com/AndrewIngram/1055c05e8525501a4d45

Implement and/or document how to perform validation depending on other nodes.

A validation function for a property just receives the value being checked, but sometimes you might want the validation to depend on the value of another field. For example, I have a field with two choices, each of the two choices causes different sub-schemas to be displayed, but I only want to validate those schemas (including their required fields), if the appropriate option has been displayed. Similarly, the actual validation rules may depend on the value of another field. I might have a country selection field, that would control the validation regex for a post code field.

Checkbox Group -- Invalid Props

function TickerField(props){
  props = props || {};
  var options = [
     {value: ['true', 'false'], name: 'option1'},
     {value: ['actions', 'noActions'], name: 'option2'},
     {value: ['option3','notOption3'], name: 'option3'}
   ];
  return (
     <Property name={props.name || 'ticker' }
          label={props.label || 'Ticker'}
          required={props.required}
          input={<CheckboxGroup options={options} /> }/>
   )
 }

This registers a proptype error Warning: Invalid prop value of type string supplied to CheckboxGroup, expected array.

Not sure if it's a bug or user error. I am supplying an array to value.

Is the github repo okay to use for a production app?

I had issues with browserify packaging the npm version of react-router, and then I downloaded the github version through npm, unaware of some drastic API changes. So now I'm using github repo version because I haven't noticed any browserify issues. It seems to work fine. I was able to get it up and running in my app (with flux btw). I know this library is under development, but is there anything I should steer clear of at the moment?

Schema definitions should allow null nodes

Let's say I'm dynamically building a schema:

<Schema name="address">
  <Property name="address_1" required />
  <Property name="address_2">
  {state.city === 'OTHER' ? <Property name="city" required /> : null}
</Schema>

As you can see, I only want to display the city field when a condition is met, otherwise I want to ignore it.

react-forms currently breaks if you supply a null as part of your schema, because the code that iterates over the code looks like this:

forEachNested(args, function(arg)  {
  utils.invariant(
    arg.name,
    'props fields should specify name property'
  );
  children[arg.name] = arg;
});

I believe adding a simple truth check for arg should fix the problem.

dirty state for validation

Having required fields be automatically invalid isn't a great UX. Would it be possible to have a dirty state that changes once the user has entered or interacted with the field? Is this already possible?

Rendering input with `type="password"`?

We are working on building a log in form using react-forms, so we need a password input. In our Schema for this form, we first tried adding a type property with a value of password, like this:

<Property type="password" name="session[password]"
  label="Password" />

But that didn't work. After some digging around, we ended up with something like this:

<Property input={<input type='password'/>} name="session[password]"
  label="Password" />

We just wanted to check with you: is this the recommended way to render a password input type? Or did we miss something important? Should we create a custom type here or tackle this from a different direction?

Thanks!

Form styling using twitter bootstrap classes

I am trying to add bootstrap classes to display the form as an inline form. I have used the following schema:

  <Schema>
    <Property
      name="fullName"
      required
      label="Full Name"
      input={<input type="text" className="form-control col-xs-4" />}
      validate={validateName}
      hint=""
      component={<Field className="form-group" />}
    />
</Schema>

This adds the classes to the div and the input tags. But the label tag also needs the classes control-label and col-sm-4. How do i do this?

Here is how the bootstrap inline form looks like:

<div class="form-group">
    <label for="inputName" class="col-sm-4 control-label">Full Name</label>
    <div class="col-sm-4">
      <input type="email" class="form-control" id="inputName" placeholder="Full Name">
    </div>
 </div>

Integrating with server-side validations

We are using react-forms in conjunction with an API that provides field-specific error messages for validations that occur on the server side. When these error messages come back from the API, we'd like to drop them in to our react-forms so they appear next to the proper field. Are there any methods that we should be looking at for this?

Validation messages should not show on fresh forms

We want to use the required property to make some of our fields required, but we think that it is a poor user experience to hit a fresh form that has a bunch of error messages on it. It would be nice if the validation messages didn't show until the field was dirtied.

Custom validation error messages?

We are wiring up some basic validations and have a desire to provide custom validation messages instead of the default "invalid value". It would be nice if the validation function could optionally return a string or throw an error that has a more descriptive message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.