- Redux Form
- API
props
props
The
propslisted on this page are are thepropsthatredux-formgenerates to give to your decorated form component. Thepropsthat you pass into your wrapped component are listed here.If you are a strict
PropTypescompletionist,redux-formexports all of thesepropTypes, so you may import them, like so:
import {reduxForm, propTypes} from 'redux-form';
class SimpleForm extends Component {
static propTypes = {
...propTypes,
// other props you might be using
}
// ...
}
anyTouched : boolean
trueif any of the fields have been marked astouched,falseotherwise.
asyncValidate : Function
A function that may be called to initiate asynchronous validation if asynchronous validation is enabled.
asyncValidating : String | boolean
This value will be either:
false- No asynchronous validation is currently happeningtrue- Asynchronous validation is currently running in preparation to submit a form- a
string- The name of the field that just blurred to trigger asynchronous validation
destroy() : Function
Destroys the form state in the Redux store. By default, this will be called for you in
componentWillUnmount().
dirty : boolean
trueif the form data has changed from its initialized values. Opposite ofpristine.
error : any
A generic error for the entire form given by the
_errorkey in the result from the synchronous validation function, the asynchronous validation, or the rejected promise fromonSubmit.
form : String
The form name that you gave to the
reduxForm()decorator or the prop you passed in to your decorated form component.
handleSubmit(eventOrSubmit) : Function
A function meant to be passed to
<form onSubmit={handleSubmit}>or to<button onClick={handleSubmit}>. It will run validation, both sync and async, and, if the form is valid, it will callthis.props.onSubmit(data)with the contents of the form data.Optionally, you may also pass your
onSubmitfunction tohandleSubmitwhich will take the place of theonSubmitprop. For example:<form onSubmit={handleSubmit(this.save.bind(this))}>If your
onSubmitfunction returns a promise, thesubmittingproperty will be set totrueuntil the promise has been resolved or rejected. If it is rejected with an object likenew SubmissionError({ field1: 'error', field2: 'error' })then the submission errors will be added to each field (to theerrorprop) just like async validation errors are. If there is an error that is not specific to any field, but applicable to the entire form, you may pass that as if it were the error for a field called_error, and it will be given as theerrorprop.To recap, there are two ways to use
handleSubmit:1. pass it a function to call
**2. pass in such a function as the onSubmit prop to your decorated component**<button onClick={handleSubmit(data => { // do something with data. validation will have been called at this point, // so you know the data is valid })}>Submit</button><MyDecoratedForm onSubmit={data => { // do something with data. validation will have been called at this point, // so you know the data is valid }}/>
initialize(data:Object) : Function
Initializes the form data to the given values. All
dirtyandpristinestate will be determined by comparing the current data with these initialized values.
invalid : boolean
trueif the form has validation errors. Opposite ofvalid.
pristine: boolean
trueif the form data is the same as its initialized values. Opposite ofdirty.
reset() : Function
Resets all the values in the form to the initialized state, making it pristine again.
submitting : boolean
Whether or not your form is currently submitting. This prop will only work if you have passed an
onSubmitfunction that returns a promise. It will betrueuntil the promise is resolved or rejected.
submitFailed : boolean
Starts as
false. IfonSubmitis called, and fails to submit for any reason,submitFailedwill be set totrue. A subsequent successful submit will set it back tofalse.
touch(...field:string) : Function
Marks the given fields as "touched" to show errors.
untouch(...field:string) : Function
Clears the "touched" flag for the given fields
valid : boolean
trueif the form passes validation (has no validation errors). Opposite ofinvalid.