Show / Hide UI Components
JourneyApps supports dynamically showing and hiding UI components in mobile apps. This is useful for use cases like:
Conditionally showing input fields based on a user's previous inputs (for example, "If you are married, fill in your spouse's details")
Showing different menu buttons on the main screen of the app depending on the user's "role" (for example, only managers see an Administration section)
... etc.
How to Show/Hide Components
In short, most view components (see Supported Components below for full details) support a show-if
or hide-if
option in the View XML that controls whether the component is hidden or shown. show-if
or hide-if
can either be a literal boolean value (true
or false
), or it can specify a variable, parameter or field that can be a string, number, object, etc. that evaluates to false or evaluates to true (see below for full details).
If a component has a required="true"
validation specified, but it is hidden, the validation will be ignored/skipped.
If you use a variable or field for show-if
or hide-if
to control visibility, you can dynamically change the value of that variable/field in order to dynamically toggle the visibility of a component (examples are provided below).
Supported Components
Any component can have a show-if
or hide-if
option, with the following exceptions:
sidebar
itself can't be hidden, but individual sidebar items may be hiddencapture-coordinates
- will still capture a location in the background
Valid Arguments to Determine Showing/Hiding
show-if
or hide-if
can either be a literal boolean value (true
or false
), or it can specify a variable, parameter or field that can be a string, number, object, etc. that evaluates to false or evaluates to true
The default JavaScript behavior is used to determine whether something evaluates to false or evaluates to true:
integer
, number
, and single-choice-integer
0
and null
are false, everything else is true
text
empty string and null
are false, everything else is true
single-choice
null
(no selection) is false, everything else is true
objects
null
is false, an object is true
location
null
is false, object is true
multiple-choice
and multiple-choice-integer
null
and empty selection is false, any selection is true
boolean
null
and false
are false, true
is true
Examples
Example - Hide/Show Inputs Based on Prior Input
In this example, we have a dropdown list to select a Province, and a dropdown list to select a City within the selected Province. The dropdown list for the City only shows once the user selected a Province. We also show a "You selected:" status message when the user selected a city.
Example - Show or Hide Based on User Role
In this example, a single mobile app will be used by both Salespeople and Technicians at a company. However, Technicians should only have access to Job Card related functionality, whereas Salespeople should only have access to Sales Quote related functionality. We accomplish this by having two menu buttons on a view that show or hide depending on what the user's role is (we use an single-choice
to store each user's role)
Example - Trigger Show/Hide From JavaScript
This example shows how we can dynamically control the showing/hiding of components from JavaScript/TypeScript. If the user presses a button, we hide or show the heading above the button.
Example - Background GPS Capturing
Note: The visibility of a GPS component cannot be dynamically controlled. It must be either visible or specifically hidden (see below).
Normally, a capture-coordinates
component in JourneyApps will show a map to the user indicating what GPS location is being captured. However, often you want to capture a GPS location in the background without displaying a map to the user. Hiding the component will cause it to continue capturing a GPS location in the background.hint
Last updated