Wrap the field component and provide Props related to the form.
import React from 'react';
import { dripFormField } from 'react-drip-form';
const Field = (props) => {
/* field component */
};
export default dripFormField(type, options)(Field);
string
'text'
Specify the type of the field. It is used when handling values.
The types that can be specified are as follows.
'text'
'checkbox'
'radio'
'select'
input[type='***']
.Note: In Type such as checkbox, radio, select etc. value handling is special, so if
type
is not specified, it will not behave as expected.
An object with the following properties.
Object
{}
You can specify the default Props For the wrapped component.
List of Props provided for wrapped components.
Apart from input
andmeta
, Props passed to the field component is passed as is.
An object with properties with the following field state.
Essentially all properties are Props which you need to assign to the field component.
string
The name
attribute of the field.
any
The value of the field.
boolean
true
A boolean indicating whether the field is checked.
It exists only if type
isradio
or checkbox
.
It is a function for detecting change of a field.
Give the Event object or the changed value as argument.
It is a function for detecting the focus of the field.
It is a function for detecting blur in the field.
An object with properties with the following meta state.
string
It is label
of the field.
string
If there are multiple errors, it will be the first error.
string[]
All error strings held by the field.
boolean
It is true
if all validation associated with the field is passed.
boolean
The opposite of meta.valid
.
boolean
true
if the field is touched even once.
input.onBlur()
is used to determine if you are touching.
boolean
The opposite of meta.untouched
.
boolean
true
if the value of any field has been changed.
boolean
The opposite of meta.dirty
.
boolean
true
if the field is validating.
Components after wrapping can specify the following Props.
All other than Props below are passed directly to Props.
string
true
A string representing the name of the field.
The string specified here will be used as a subscript to values
.
any
false
Specify the value of the field.
The value specified here will be used as the initial value.
Also, if it is detected that componentWillReceiveProps()
is not equivalent, overwrite the current form value.
string
null
false
Specify the label of the field. It is mainly used in error messages.
(value: any, name: string): any
null
false
Specify a function for parsing the handled value.
It is called after input.onChange ()
is executed.
(value: any, name: string): any
(value: any): any => value == null ? '' : value
false
Specify the function that formats the value used for display.
It is called with render ()
. (It is just before passing it to Props of WrappedComponent)
Object
null
false
You can specify a validation rule.
Please refer to drip-form-validator
Built-in Rules for specifiable rules.
<Field
name="username"
validations={{
required: true,
max: 255,
}}
/>
Object
null
false
You can specify Normalizers.
Please refer to drip-form-validator
Built-in Normalizers for specifiable rules.
<Field
name="rating"
normalizers={{
between: {
min: 0,
max: 100,
},
}}
/>
Object
null
false
Specify the error message corresponding to the validation rule.
<Field
name="username"
messages={{
required: 'Username is required!',
}}
/>
Function
null
false
Called when the value of the field has changed. (After executing input.onChange ()
)
Function
null
false
Called when the field is out of focus. (After executing input.onBlur ()
)
Function
null
false
Called when the field is focused. (After executing input.onFocus()
)