field (instance)
Instance of FieldCreator
Description
field
is responsible for creating fields required by createForm
/FormConfig
.
It specifies a member function for each HTML input
type, select
and textarea
. There is also a function for raw
fields. A custom field can be attached using addField
.
Members
checkbox
(initialChecked: boolean = false) => CheckboxField
color
(initialValue: string = "") => TextField
date
(initialValue: string = "") => TextField
datetimeLocal
(initialValue: string = "") => TextField
(initialValue: string = "") => TextField
image
(initialValue: string = "") => TextField
month
(initialValue: string = "") => TextField
number
(initialValue: string = "") => TextField
password
(initialValue: string = "") => TextField
radio
(initialValue: string = "") => RadioField
- name
(value: string) => RadioField
value for thename
property passed to<input />
's - unselectable
(value = true) => RadioField
allows to unselect a radio option by clicking on it again
The radio
field will produce a function of following type for the fields
property of useFluentForm
:
This function will allow to specify different values for each radio <input />
:
range
(initialValue: string = "") => TextField
raw
<ValueType>(initialValue: ValueType) => RawField
- withValueProp
(valueProp: string) => void
name of thevalue
property of the component - withOnChangeProp
(onChangeProp: string) => void
name of theonChange
property of the component - withOnBlurProp
(onBlurProp: string) => void
name of theonBlur
property of the component
For components like react-datepicker
it's not necessary to implement a custom field.
react-fluent-form
comes with a raw field type which works for components with following characteristics:
- it has
value
-like and aonChange
-like prop value
has the same type as the first parameter ofonChange
handler.- it optionally has a
onBlur
-like prop to indicate when the field is touched
*-like means it must not have the same name, but the same type. E.g. the value
prop in react-datepicker
is called selected
.
For raw fields it's required to pass an initial value, otherwise it will be undefined.
The type of fields
object would look like this:
search
(initialValue: string = "") => TextField
select
(initialValue: string = "") => SelectField
The select
field will produce an object of following type for the fields
property of useFluentForm
:
While the select
property needs to be spreaded onto <select />
, the option
property will allow to specify differnet values for each <option />
:
tel
(initialValue: string = "") => TextField
text
(initialValue: string = "") => TextField
textarea
(initialValue: string = "") => TextAreaField
time
(initialValue: string = "") => TextField
url
(initialValue: string = "") => TextField
week
(initialValue: string = "") => TextField