Options
Introduction
Passing options to the createField()
high-order component allows to control the behavior of the created field. That is extremely useful when implementing custom fields, or integrating third-party solutions to work with React Advanced Form.
You don't have to configure any of these options. Please use the defaults exposed with Field presets, unless you're customizing a field's behavior on purpose.
valuePropName
valuePropName
Type |
|
Default value |
|
Some fields update a prop different from the value
upon the interaction with them. For example, a checkbox updates its checked
prop. Provide the prop name to update on field's onChange
using this option, in case it differs from value
.
initialValue
initialValue
Type |
|
Default value |
|
Initial value of all instances of a field. Useful for cases when the initial value of a field is different from an empty string.
Note that initialValue
is then mapped using mapValue
option.
assertValue
assertValue
Type |
|
Default value |
|
A predicate function stating that a field contains some value.
Useful for describing a proper validation behavior for a custom field where its value is represented using a complex instance (i.e. Object).
In the example above, we have created a field that accepts an array of integers as its value
, and transforms it into the { from, to }
Object to be stored in the field's state. In order to have a proper validation logic, such as validation on mount, we need to supply a custom predicate that describes when our field has some actual value.
mapValue
mapValue
Type |
|
Default value |
|
Maps a "raw" field's value into its representative in the field's state.
This only affects external value updates (i.e. receiving next value
prop, resetting or clearing a field). This has no effect when the native onChange
callback is dispatched.
allowMultiple
allowMultiple
Type |
|
Default value |
|
Allows multiple instances of a field with the same name within a single form's scope. This affects both form and Field group scopes.
By default, field's name is the unique identifier that prevents the registration of duplicate fields. However, some field types (i.e. radio button, or your custom field) may want to render multiple field components with the same name.
mapPropsToField
mapPropsToField
Definition
Type |
|
Default value |
|
Parameters
Param name | Type | Description |
|
| Value prop name of a field. |
|
| Raw field component's props. |
|
| Reference to the field's record in the form's state. |
|
|
Each field has its record stored in the internal state of the Form
component. That record is composed based on the field's props, but may (and sometimes must) be altered to provide proper field functionality.
enforceProps
enforceProps
Definition
Type |
|
Default value |
|
Parameters
Param name | Type | Description |
|
| Raw field component's props. |
|
| Field record in a form's state. |
Allows enforcing an Object of props which will override the Field's registration record within the form.
beforeRegister
beforeRegister
Definition
Type |
|
Default value |
|
Parameters
Param name | Type | Description |
|
| Original field props. |
|
| Reference to all fields. |
Applies additional transformation or logic to the field right before it is registered. Allows to completely prevent field registration when false
is returned from this method.
Modifying field's record
Preventing field registration
Returns false
from beforeRegister
method to prevent a field from registering its record in the parent form's state.
shouldValidateOnMount
shouldValidateOnMount
Definition
Type |
|
Default value |
Determines whether a field should be validated upon mounting, if it has value (its assertValue
resolves).
Parameters
Param name | Type | Description |
|
| Dynamic key that is value prop name, with value being a field's value. |
|
| Value prop name of a field. |
|
| Reference to a field's record in a form's state. |
|
|
Determines whether a field should be validated upon mount.
serialize
serialize
Definition
Type |
|
Default value |
|
Parameters
Param name | Type | Description |
|
| Original serialized value of a field. |
Returns the next serialization payload of a field.
Useful to provide transformations to a field's value upon form serialization.
Note that serialize
works complementary with Form.props.onSerialize
, and it executed before the form's serialization transformer.
Last updated