Formulas for Various properties (Enabled/Visibility/Value)

Formulas for Various properties (Enabled/Visibility/Value)

Introduction to Formulas in Openous

Javascript-based expressions called “Formulas” can be used throughout any Openous control property. Formulas can return any type of value. The form special variable is available in order to provide access to the parent form control/object, its methods and all included controls. Property values that represent formulas, should be marked with an equals (=) sign in the beginning, so that Openous execution engine understands that what follows is a javascript expression. For example, if you want a control's height to be dynamically calculated based on a user's input on another control, you can place the following formula on the designer:


=(form.GetControl("txt_UserHeight").GetNumericValue() + 30) + "px"

Supported Shortcuts/Expressions

Apart from basic javascript syntax, the following special expressions are supported:

Expression

Description

{ControlName}

Returns the value of the control with the specified name. Equivalent to the following javascript expression:

form.GetControl("ControlName").GetValue();


sample formula:

"The item title is: " + {Title}

{name:ControlName}

Applicable when the control with the specified is a lookup control (for example, ComboBox). Returns the property of the selected item (object) that is displayed (the one entered in the Lookup Display Field).


Equivalent to the javascript expression:

form.GetControl("ControlName").GetValuePath(form.GetControl("ControlName").LookupDisplayField)


sample formula:

"The selected country is" + {name:Country}

{value:ControlName}

Applicable when the control with the specified is a lookup control (for example, ComboBox). Returns the property of the selected item (object) that is used as a value (the one entered in the Lookup Value Field – not the one that is displayed).


Equivalent to the javascript expression:

form.GetControl("ControlName").GetValuePath(form.GetControl("ControlName").LookupValueField)


sample formula:

"The selected country ID is: " + {value:Country}

{ControlName#PropertyName}

Applicable when the control with the specified is a lookup control (for example, ComboBox). Returns the property [PropertyName] of the selected item (object) that is used as a value.


Equivalent to the javascript expression:

form.GetControl("ControlName").GetValuePath("PropertyName")


sample formula:

"The selected country’s Code is: " + {Country#Code}

{ControlName.PropertyName}

Applicable for ListBox controls. Returns the property [PropertyName] of the listbox’s selected item (object).


Equivalent to the javascript expression:

form.GetControl("ControlName").GetSelectedItem()["PropertyName"]


sample formula:

"The selected row ID is: " + {Details.ID}



Enabled and Visibility Formulas

Formulas can be used to “Enabled Formula” and “Visibility Formula” properties. The expressions you enter in this property will evaluate on runtime whether a control is Visible or Enabled.



Examples:

  1. The following Visibility formula, hides the control when the user inputs “hide” in the Title textbox:
form.GetControl("Title").GetValue() != "hide" 
or alternatively
{Title} != "hide"

  1. The following Enabled formula enables the control only when the user selects “US Dollars” in a  ComboBox with the name “Currency”:
form.GetControl("Currency").GetValuePath("CurrencyCode") == "USD" 
or alternatively
{Currency#CurrencyCode} == "USD"

In the above example, the display field of the Combobox can also be used:
{name:Currency} == "US Dollars"