This page demonstrates conditional fields. This feature is
useful, in a form where some fields should be entered only when other fields are set to some value.
There are two possible options:
zpFormDisplayWhen=callbackFunction - when callbackFunction returns true -
the dependant field is shown. When false - hiden. When the fields are hidden
they don't use any space in the form.
zpFormVisibleWhen=callbackFunction - when callbackFunction returns true -
the dependant field is shown. When false - hiden. In this
case the fields use the space even when they're hidden.
The callback functions should be defined before creating the Zapatec.Form object.
Using conditionalEvents config option you can define events when conditional fields will be checked. Possible values:
focus - when field gets focus
blur - when field loses focus
keydown - when some field in the form fires "keydown" event
keypress - when some field in the form fires "keypress" event
keyup - when some field in the form fires "keyup" event
valueChanged - when value in field changes
booleanValueChanged - when checkbox/radio button field is changed
Usually you will need to use conditionalEvents: ["booleanValueChanged"] or conditionalEvents: ["valueChanged"]. By default - conditional fields are checked at all form events.
This page demonstrates how a form can conditionally display or hide fields based on the return value of a callback.
This feature is particularly useful for a form in which some fields should be filled only when other fields are set to a particular value.
The conditional fields feature is implemented by a callback associated with the zpFormDisplayWhen or zpFormVisible property. When the callback function returns true, the dependent field is displayed. When the callback returns false, the field is hidden.
If you use the zpFormDisplayWhen property, hidden fields do not use any space in the form. If you use
zpFormVisibleWhen, fields always use the space, even when they are hidden.
Define the callback functions before creating the Zapatec.Form object.