Conditional Expressions

Use logic to control when form elements and fields are hidden, visible, required or optional.

Overview

When building Forms within Kinetic, admins can use Conditional Expressions to inject logic and guide users down the right path. Conditional expressions can be used to control the visibility of a Field or Element within a form, as well as to control weather a page displays or not.

Conditional Expressions are written in javascript and can include variables like Field values or attributes defined within the platform.

Within the Kinetic Form Builder the following variables available by default for use within conditional expressions:

  • space
  • kapp
  • form
  • values
  • identity

Examples

Text , Radio, Dropdown

Below is an example of a section that should only be displayed if the answer to the field "Employee Department" is equal to "Accounting"

580

Conditional Expression based upon field value

Checkbox Example

Below is an example of using a conditional expression that includes another field that is a checkbox question. In this case, since checkbox fields can have multiple values, we use the indexOf javascript function to test if the value "Blue" was selected.

573

Conditional Expression with Checkbox Field

Using Javascript to hide and show Fields programmatically

There may be times when you would want to leverage the javascript functionalities available to control display and validation of a field:

K('field[Field Name]').hide() 
K('field[Field Name]').show() 
K('field[Field Name]').disable()
K('field[Field Name]').enable()

This will allow you to control display of a field directly from the javascript, which does allow you to control display of a field by field name in shared javascript files. However, this may cause conflicts. For example, if you define a “Visible” condition in the builder of “Hidden” and then call the show method, eventually the form will self-correct and hide the field again. Leaving these conditions to their default state should allow you to use the functions in JavaScript event code.

This method also has the consideration of being difficult to troubleshoot. If you have fields displaying incorrectly, it can be difficult to track down the source for this in the javascript files that may be present on the server.

Given that the similar functionality could be acquired by having a particular field on those shared forms and setting that field to a value that, per the built in conditional, controls the display in the desired way, there is little to be said for this method unless it is something where the conditional is likely to be updated frequently. Then this method could prevent you from having to go into all the forms to update the conditional.