Options
Last updated
Last updated
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
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
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
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
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
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
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
Allows enforcing an Object of props which will override the Field's registration record within the form.
beforeRegister
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.
Returns false
from beforeRegister
method to prevent a field from registering its record in the parent form's state.
shouldValidateOnMount
Determines whether a field should be validated upon mounting, if it has value (its assertValue
resolves).
Determines whether a field should be validated upon mount.
serialize
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.
Type
string
Default value
"value"
Type
any
Default value
''
Type
(params) => boolean
Default value
({ value }) => !!value
Type
any
Default value
(value) => value
Type
boolean
Default value
false
Type
(params) => Object
Default value
({ fieldRecord }) => fieldRecord
Param name
Type
Description
valuePropName
string
Value prop name of a field.
props
Object
Raw field component's props.
fieldRecord
Object
Reference to the field's record in the form's state.
context
Object
Type
(params) => Object
Default value
() => ({})
Param name
Type
Description
props
string
Raw field component's props.
contextProps
Object
Field record in a form's state.
Type
(params) => Object
Default value
({ fieldProps }) => fieldProps
Param name
Type
Description
fieldProps
string
Original field props.
fields
Object
Reference to all fields.
Type
(params) => boolean
Default value
Param name
Type
Description
[valuePropName]
any
Dynamic key that is value prop name, with value being a field's value.
valuePropName
string
Value prop name of a field.
fieldRecord
string
Reference to a field's record in a form's state.
context
Object
Type
(params) => any
Default value
(value) => value
Param name
Type
Description
value
any
Original serialized value of a field.