Selectively Display a Field
Within a dynamic form, you can hide a field by default and make it visible only after something else happens in the page.
For example, suppose you've created a dynamic form for entering data about films with these fields:
- Film title, which is an input field
- Director, also an input field
- Year of release, input field
- A toggle switch, which indicates whether subtitles are available
- An input field for entering the available subtitle languages.
In this scenario, you want the field for entering subtitle languages to be hidden when no subtitles are available, like this:
When the user changes the Are subtitles available? toggle to On, the field for entering subtitle languages becomes visible:
Dynamic forms are controlled by the display logic you specify in a rule set. A rule specifies both a condition—in this case, whether the toggle switch is set to On—as well as a layout to apply to the dynamic form at runtime. In this case, that layout will show the Subtitle Languages
field in the form.
After reading through this topic, you should have a basic understanding of how rule sets and layouts work, which you can apply to real-world tasks you may have at your site.
You can now view the page in Live mode to check your work. Notice that the Subtitle Languages
field is hidden by default. If you toggle the Are subtitles available?
switch to On, the Subtitle Languages
field is displayed:
Description of the illustration hiddenfield-createform-visible.png
Let's do a quick re-cap of what's happening behind the scenes:
- The user toggles the
Are subtitles available?
switch to On. - The event listener detects that an
On 'value-item'
event has occurred, and fires off theSwitchValueChangeChain
action chain. - The action chain has one action, which is to assign a value of true to the
showLanguageInput
variable. - Because the Bind If component's Test property is set to the value of
showLanguageInput
, and that value is now true, theSubtitle Languages
field (which is wrapped in the Bind If component) can now be displayed.