useForm() Hook
Sets up the form hook for use with HTML form elements.
Signature:function useForm<Values extends FormValues>(initialValues: Values,onSubmit: (values: Values) => void | Promise<void>,options?: FormOptions<Values>): FormiteHtmlForm<Values>
Parameters
Parameter | Type | Description |
---|---|---|
initialValues | Values | Initial values of the form |
onSubmit | (values: Values) => void ǀ Promise<void> | The function that is called when submitting the form. |
options | FormOptions<Values> | Optional Form options |
FormiteHtmlForm<Values>
The forms state and API, a Form component and a handleSubmit callback.
interface FormiteHtmlForm<Values extends FormValues> extends FormiteForm<Values> {Form: (props: React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>) => JSX.Element;handleSubmit: (ev: React.FormEvent<HTMLFormElement>) => void;}
Remarks
All initial field values should be set even if they are undefined.
useInput() Hook
Sets up a form's field hook for use with an HTML input element.
Signature:function useInput(field: Field, onValidate?: ValidateFieldHandler, metadata?: any): {value: string | undefined;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;};
Parameters
Parameter | Type | Description |
---|---|---|
field | Field | The Field to connect to an input component. |
onValidate | ValidateFieldHandler | An optional callback function to validate the field. |
metadata | any | An optional data value that is stored with the . |
{value: string | undefined;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;}
The properties to pass to the HTML input component.
Example
<input type="text" {...useInput(fields.stringField)} />
useCheckbox() Hook
Sets up a form's field hook for use with an HTML checkbox element.
Signature:function useCheckbox(field: Field<boolean>, onValidate?: ValidateFieldHandler, metadata?: any): {checked: boolean | undefined;type: string;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;};
Parameters
Parameter | Type | Description |
---|---|---|
field | Field<boolean> | The Field to connect to an input component. |
onValidate | ValidateFieldHandler | An optional callback function to validate the field. |
metadata | any | An optional data value that is stored with the . |
{checked: boolean | undefined;type: string;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;}
The properties to pass to the HTML input component.
Example
<input {...useCheckbox(fields.aBooleanField)} />
useRadioButton() Hook
Sets up a form's field hook for use with an HTML radio button element.
Signature:function useRadioButton(field: Field, value: string | number, onValidate?: ValidateFieldHandler, metadata?: any): {checked: boolean;type: string;value: string | number;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;};
Parameters
Parameter | Type | Description |
---|---|---|
field | Field | The Field to connect to an input component. |
value | string ǀ number | The value that should be assigned to the field when the radio button in the group is selected. |
onValidate | ValidateFieldHandler | An optional callback function to validate the field. |
metadata | any | An optional data value that is stored with the . |
{checked: boolean;type: string;value: string | number;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;}
The properties to pass to the HTML input component.
Example
<input {...useRadioButton(fields.someField, "A_VALUE")} />
useSelect() Hook
Sets up a form's field hook for use with an HTML select element.
Signature:function useSelect(field: Field, onValidate?: ValidateFieldHandler, metadata?: any): {value: string | string[] | undefined;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLSelectElement>) => void;};
Parameters
Parameter | Type | Description |
---|---|---|
field | Field | The Field to connect to a select component. |
onValidate | ValidateFieldHandler | An optional callback function to validate the field. |
metadata | any | An optional data value that is stored with the . |
{value: string | string[] | undefined;onBlur: () => void;onChange: (ev: React.ChangeEvent<HTMLSelectElement>) => void;}
The properties to pass to the HTML select component.
Example
<select {...useSelect(fields.someField)}><option value="VALUE_1">Option A</option><option value="VALUE_2">Option B</option></select>