About this article
IfElse() is a commonly used function that outputs values based on a condition. The function is commonly used for setting a binding to certain text or setting a property based on user input. Rather than nesting IfElse() statements for multiple comparisons then use a Switch() function.
Pre-requisites
|
Syntax
Syntax | {{IfElse(Condition, TrueValue, FalseValue)}} |
Input | Condition |
Output | TrueValue/FalseValue |
Example 1
Using the IfElse() function to set visibility of a binding based on the value of Form.Subject
Binding | {{IfElse(Equals(Form.Subject, "Test"), VisibilityType.Hidden, VisibilityType.Visible)}} |
Input | Form.Subject = "Test" |
Condition | True |
Output | VisibilityType.Hidden |
Example 2
Using the IfElse() function to insert product information based on a contains() condition.
Binding | {{IfElse(Contains(Form.Subject, "Product A"), "Product A is $100", "Product B is $200")}} |
Input | Form.Subject = "We are showcasing Product A" |
Condition | True |
Output | "Product A is $100" |
Example 3
Using the IfElse() function with a checkbox to determine visibility of a binding.
Binding | {{IfElse(Form.CheckboxInclude, VisibilityType.Visible, VisibilityType.Hidden)}} |
Input | Checkbox is not checked |
Condition | False |
Output | VisibilityType.Hidden |
Example 4
Using the IfElse() function with a checkbox to determine visibility of a binding.
Show the text only if Product A and C are checked.
Binding | {{IfElse(Form.ProductA,IfElse(Form.ProductC, VisibilityType.Visible ,VisibilityType.Hidden),VisibilityType.Hidden)}} | |
Input | Form.ProductA = "☑", Form.ProductC = "☑" | Form.ProductA = "☐", Form.ProductC = "☑" |
Output | "You have selected Product A and C" | Hidden text |
Example 5
Using the IfElse() function with a checkbox to determine visibility of a binding.
Show the text only if Product A and C are checked, and Product B is unchecked.
Binding | {{IfElse(Form.ProductA,IfElse(Not(Form.ProductB), IfElse(Form.ProductC,VisibilityType.Visible,VisibilityType.Hidden),VisibilityType.Hidden),VisibilityType.Hidden)}} | |
Input | Form.ProductA = "☑", Form.ProductB = "☐", Form.ProductC = "☑" | Form.ProductA = "☑", Form.ProductB = "☑", Form.ProductC = "☑" |
Output | "You have only selected Product A and C" | Hidden text |
Example 6
Using the IfElse() function and Not() condition for determining if the text in a form field is not equal to something.
Binding | {{IfElse(Not(Equals(Form.Subject, "Product A")), "Description of all other products", "Description of product A")}} |
Input | Form.Subject = "As you can see our products are compliant" |
Condition | True |
Output | "Description of all other products" |
Related articles
Comments
0 comments
Article is closed for comments.