Dependent Field
Functions
DependentField
▸ DependentField<Values, Value, Key, Ref, DependentValues>(props): Element
A DependentField is a field that depends on the value of another field or fields in
its owner Form. The DependentField has the exact same interface except with the added
ability to respond to changes in other fields within its parent form.
Example Usage:
<DependentField
name="favoriteDrink"
dependencies={(values) => ({ dob: values.dob })}
validate={(_, { dob }) => {
if (dob <= 21) {
return "Must be 21 years old"
}
}}
onDependenciesChange={(dependencies, actions) => {
if (dependencies.dob <= 21) {
actions.setValue("N/A");
}
}}
/>
Type parameters
| Name | Type |
|---|---|
Values | extends FormzValues = FormzValues |
Value | extends FieldValue = FieldValue |
Key | extends string = string |
Ref | HTMLInputElement |
DependentValues | extends Partial<Values> = Partial<Values> |
Parameters
| Name | Type | Description |
|---|---|---|
props | DependentFieldProps<Values, Value, Key, Ref, DependentValues> | FieldProps - The react props for the field component. |
Returns
Element
Defined in
packages/react-formz-web/src/components/DependentField/DependentField.tsx:66