- Redux Form
- API
props
props #
The
propslisted on this page 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 React.Component {
static propTypes = {
...propTypes
// other props you might be using
}
// ...
}
anyTouched : boolean #
trueif any of the fields have been marked astouched,falseotherwise.
array : Object #
A set of pre-bound action creators for you to operate on array fields in your form.
array.insert(field:String, index:Number, value:Any) : Function#
Inserts a value into the given array field in your form. This is a bound action creator, so it returns nothing.
array.move(field:String, from:Number, to:Number) : Function#
Moves a value at the given
fromindex to the giventoindex in the given array field in your form. This is a bound action creator, so it returns nothing.
array.pop(field:String) : Function#
Pops a value off of the end of a given array field in your form. This is a bound action creator, so it returns nothing.
array.push(field:String, value:Any) : Function#
Pushes the given value onto the end of the given array field in your form. This is a bound action creator, so it returns nothing.
array.remove(field:String, index:Number) : Function#
Removes a value at the given index from the given array field in your form. This is a bound action creator, so it returns nothing.
array.removeAll(field:String) : Function#
Removes all the values from the given array field in your form. This is a bound action creator, so it returns nothing.
array.shift(field:String) : Function#
Shifts a value out of the beginning of the given array in your form. This is a bound action creator, so it returns nothing.
array.splice(field:String, index:Number, removeNum:Number, value:Any) : Function#
Performs an
Array.spliceoperation on the given array in your form. This is a bound action creator, so it returns nothing.
array.swap(field:String, indexA:Number, indexB:Number) : Function#
Swaps two values at the given indexes of the given array field in your form. This is a bound action creator, so it returns nothing.
array.unshift(field:String, value:Any) : Function#
Unshifts the given value into the beginning of the given array field in your form. This is a bound action creator, so it returns nothing.
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
autofill(field:String, value:any) : Function #
Sets the value and marks the field as
autofilledin the Redux Store. This is useful when a field needs to be set programmatically, but in a way that lets the user know (via a styling change using theautofilledprop inField) that it has been autofilled for them programmatically. This is a bound action creator, so it returns nothing.
blur(field:String, value:any) : Function #
Marks a field as blurred in the Redux store. This is a bound action creator, so it returns nothing.
change(field:String, value:any) : Function #
Changes the value of a field in the Redux store. This is a bound action creator, so it returns nothing. You could get current field-value & form-values while
valueis a function, For example:change(field, (fieldValue, allValues) => {})
clearAsyncError(field:String) : Function #
Clear async error of a field in the Redux store. This is a bound action creator, so it returns nothing.
destroy() : Function #
Destroys the form state in the Redux store. By default, this will be called for you in
componentWillUnmount(). This is a bound action creator, so it returns nothing.
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
;<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>
2. pass in such a function as the onSubmit prop to your decorated component
;<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. This is a bound action creator, so it returns nothing.
initialized : boolean #
truethe form has been initialized with initial values,falseotherwise.
initialValues : Object #
The same initialValues object passed to
reduxFormto initialize the form data.
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. This is a bound action creator, so it returns nothing.
resetSection(...sections:String) : Function #
Resets all the values in the form sections to the initialized state, making it pristine again. This is a bound action creator, so it returns nothing.
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.
submitSucceeded : boolean #
Starts as
false. IfonSubmitis called, and succeed to submit ,submitSucceededwill be set totrue. A subsequent unsuccessful submit will set it back tofalse.
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.
touch(...field:string) : Function #
Marks the given fields as "touched" to show errors. This is a bound action creator, so it returns nothing.
untouch(...field:string) : Function #
Clears the "touched" flag for the given fields This is a bound action creator, so it returns nothing.
valid : boolean #
trueif the form passes validation (has no validation errors). Opposite ofinvalid.
warning : any #
A generic warning for the entire form given by the
_warningkey in the result from the synchronous warning function.