Skip to main content

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

NameType
Valuesextends FormzValues = FormzValues
Valueextends FieldValue = FieldValue
Keyextends string = string
RefHTMLInputElement
DependentValuesextends Partial<Values> = Partial<Values>

Parameters

NameTypeDescription
propsDependentFieldProps<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