Skip to main content

Validation Rules

1. Introduction to Validation RulesDirect link to 1. Introduction to Validation Rules

The Rules Manager is a cornerstone of the Web Modeler, empowering you to create dynamic and intelligent user interfaces. It allows you to define screen-specific rules that control the behavior of your components, leading to sophisticated forms that adapt in real-time to user input and application state.

By setting rules, you can control whether a component is available, visible, required, or disabled. This ensures that users are only presented with relevant information, guiding them through complex data entry processes and reducing errors.

The rules of a widget are set in the Validation card of the configuration panel: select the widget on the canvas, then open the Validation card on the right.

The Validation card of the selected widget, in the configuration panel of the builder: one row per screen, one column per rule.
The Validation card of the selected widget, in the configuration panel of the builder: one row per screen, one column per rule.

2. The Four Fundamental Rules ExplainedDirect link to 2. The Four Fundamental Rules Explained

The Rules Manager operates on four fundamental properties that you can configure for any widget on a screen. Understanding each is key to building effective user experiences.

  • Available: Determines if the widget is loaded and exists within the page's data model for that screen. If a widget is not available, its data cannot be accessed, manipulated, or submitted. Available is always an on/off switch: it cannot hold a condition.

    • Practical Example: In an approval workflow, a "Manager's Justification" field is made available only on the "Manager Review" screen, not on the initial "Submission" screen.
  • Visible: Controls whether the user can see the widget. A component can be available (holding data) but hidden from view.

    • Practical Example: A "Shipping Address" form is hidden until the user checks a "Ship to a different address" box. This simplifies the initial view while keeping the data fields ready.
  • Required: Marks an input field as mandatory. The form cannot be submitted if a required field is empty.

    • Practical Example: An "Email Address" field in a user registration form is marked as required to ensure essential contact information is always collected.
  • Disabled (column Disable): Determines if a user can interact with a widget. A disabled widget is visible but "grayed out" and cannot be edited. Its value is still part of the form's data.

    • Practical Example: A "Submit" button remains disabled until all required fields are correctly filled out, preventing incomplete submissions.

Visible, Required and Disable accept either a fixed value (a switch) or a condition (see section 4). For a section that can be collapsed, the last column is Collapse instead of Disable: it sets whether the section is folded on that screen, and it does not accept a condition (see section 3.4).

3. Navigating the Rules Manager InterfaceDirect link to 3. Navigating the Rules Manager Interface

The Validation card provides a centralized table to configure these rules for each component on each screen, enabling you to dynamically control what users see and do.

3.1. Interface BreakdownDirect link to 3.1. Interface Breakdown

When All Screens is selected at the top of the canvas, the card is a grid where each row represents a screen of the interface and each column one of the four rules, with its icon.

The Validation card in the All Screens view: a switch per screen for Available, Visible, Required and Disable, and the Advanced Setting link.
The Validation card in the All Screens view: a switch per screen for Available, Visible, Required and Disable, and the Advanced Setting link.
  • Screens: Lists all the screens of the interface (e.g., "Création", "Correction", "Validation manager"), as managed with the All Screens selector of the canvas.
  • Available / Visible / Required / Disable switches: Simple on/off switches for enabling or disabling a rule unconditionally on one screen.
  • Column titles: A click on a column title (Available, Visible, Required, Disable) switches that rule on every screen at once: all the screens take the opposite of the value of the first screen. The click replaces with a fixed value any condition already written in that column; if the first screen holds a condition, all the screens are switched on. On a container, the click also applies to all the widgets inside it: the Available title for every container, the Visible title for Tabs, Drawer and Popup. The other titles of a container open a dialog or an editor instead (see section 3.4).
  • Advanced Setting: The link under the table replaces the Visible, Required and Disable switches with pencil buttons (Available stays a switch). A click on a pencil opens the Advanced Setting Condition editor for that rule on that screen (see section 3.3). The link then becomes Easy Setting, which brings the switches back; a rule that holds a condition keeps its pencil button. Containers have their own controls: see section 3.4.
After a click on Advanced Setting: a pencil button per rule and per screen opens the condition editor; Easy Setting brings the switches back.
After a click on Advanced Setting: a pencil button per rule and per screen opens the condition editor; Easy Setting brings the switches back.

3.2. One Screen at a TimeDirect link to 3.2. One Screen at a Time

When you pick a screen in the All Screens selector of the canvas, the Validation card only shows that screen: one row each for Visible, Required and Disable, with its switch and a pencil button that opens the condition editor. The canvas also shows the page as it will be on that screen: hidden widgets are faded and disabled fields are grayed. Available is set in the All Screens view.

To come back to the full view, open the selector, which now shows the name of the screen, and click the eye button of the All Screens row at the top of the list.

The screen 'Validation manager' selected: the card shows the rules of this screen only, and the canvas grays out the fields disabled on this screen.
The screen 'Validation manager' selected: the card shows the rules of this screen only, and the canvas grays out the fields disabled on this screen.

3.3. The Condition EditorDirect link to 3.3. The Condition Editor

The Advanced Setting Condition editor opens from a pencil button. Its help reminds you: Write a condition to apply, You can use any variable in the interface with {{}}. Type a JavaScript expression in the text area (see section 4), then:

  • Apply sets the condition for this rule on the screen of the row you clicked;
  • Apply to All screens sets the same condition for this rule on every screen of the interface.
Save the interface after applying a condition

Apply and Apply to All screens do not count as a change: the automatic save does not start and the indicator at the top of the panel stays on Saved. The same goes for the Apply to all Grid sub-widgets dialog (see section 3.4) and for the clicks on column titles (see section 3.1). Click Save interface in the right rail, or the Saved indicator, to keep them. Otherwise they are lost when you leave the page, unless a later change has started the automatic save.

3.4. Grid, Section, Form, Tabs, Drawer and PopupDirect link to 3.4. Grid, Section, Form, Tabs, Drawer and Popup

For a container (Grid, Section, Form, Tabs, Drawer or Popup), Required and Disable are not switches but a button. It opens Apply to all Grid sub-widgets, which sets the rule for the container and for every widget inside it:

  • Require All / UnRequire All (for Disable: Disable All / UnDisable All);
  • Advanced Setting: a condition, typed in the field that appears;
  • Apply applies the choice on the screen of the row; from a column title, on every screen.

For a Grid, a click on the Visible column title opens the condition editor with Apply to All screens only. A Grid inside a Tabs, Drawer or Popup is not switched by the Visible title of its container: the same editor opens for it.

Apply to all Grid sub-widgets: require (or disable) the container and all its widgets at once, or give them a condition.
Apply to all Grid sub-widgets: require (or disable) the container and all its widgets at once, or give them a condition.

Section and Form are Grids with the Collapse option on (Style card), like any Grid where you turn this option on. Depending on how a section was created, its badge in the configuration panel shows Section or Grid. Their Required column is the button described above, but the last column is different:

  • On a row, Collapse is always a switch, even after Advanced Setting: it folds or opens the section on that screen, and does nothing else, unless Form is on: the fields of the folded block are then disabled.
  • Collapse does not accept a condition. In the view of one screen the row has a pencil button, but a condition written there has no effect: the section stays open. With Form on, the condition disables the fields of the block, which stays open.
  • A click on the Collapse column title opens the dialog above with Disable All / UnDisable All. Disable All folds the section on every screen and disables all its fields. To fold the section only, use the switches of the rows. With Advanced Setting, the condition applies to the fields and the section stays open.
The Validation card of a Section after Advanced Setting: pencil buttons for Visible, the button of the dialog for Required, and Collapse still a switch.
The Validation card of a Section after Advanced Setting: pencil buttons for Visible, the button of the dialog for Required, and Collapse still a switch.

For a Grid with the Loop option, Required is also the button. On a row, Disable works as for any widget: on a screen where it is on, the buttons that add and remove rows are not shown. But a click on the Disable column title opens the dialog above, and Disable All also disables all the fields of the loop.

4. Building Dynamic Forms with Conditional LogicDirect link to 4. Building Dynamic Forms with Conditional Logic

The true power of the Rules Manager is unlocked when you use conditional logic. With the pencil button of a rule (after Advanced Setting, or in the view of one screen), you can define a JavaScript expression that evaluates in real-time.

In a condition, {{field}} (or #field) is the value of the widget whose model is field, or of the model variable field (a process variable that no widget holds); {{SF_connectedUser.firstName}} reads the connected user. The rest is plain JavaScript: comparisons, &&, ||, function calls.

4.1. Example: Conditional VisibilityDirect link to 4.1. Example: Conditional Visibility

A classic use case is displaying a "State/Province" field only when the selected country requires it.

  1. Scenario: We have two widgets:

    • A dropdown menu with the model name country.
    • A text input field with the model name state.
  2. Goal: The state field should only be visible if the selected country is "United States" or "Canada".

  3. Implementation:

    1. In the Web Modeler, select the state widget.
    2. In its Validation card, click Advanced Setting (or pick the relevant screen in the All Screens selector).
    3. On the row of the relevant screen, click the pencil button of the Visible column.
    4. In the Advanced Setting Condition editor, enter the following JavaScript expression, then click Apply (or Apply to All screens):
{{country}} === 'United States' || {{country}} === 'Canada'
Implementing a conditional visibility rule. The 'state' field will now appear only when a user selects 'United States' or 'Canada'.
Implementing a conditional visibility rule. The 'state' field will now appear only when a user selects 'United States' or 'Canada'.

This expression tells the UI to show the state field only when the condition is met. For all other countries, it will remain hidden, creating a cleaner and more contextual form.

4.2. How Rules Are EvaluatedDirect link to 4.2. How Rules Are Evaluated

When the page opens, each condition is turned into an expression of the page and evaluated again whenever the data it reads changes. On pages that run on the current engine (see Pages on an old version of the engine):

  • A rule that fails counts as false. If the condition throws an error while it is evaluated (data not loaded yet, a function that does not exist…), the rule is false: the widget is hidden (Visible), not required (Required) or editable (Disable), and the rest of the page keeps working. The rule is evaluated again as soon as the data changes.
  • A rule that is not valid JavaScript is ignored. It counts as false, the page still opens, and the browser console lists it after the message SoftyFlow: parts of this page are ignored because they are not valid (for example rule "{{amount}} >" is not a valid expression).
  • Property accesses are safe. {{supplier}}.address.city === 'Paris' is read as models?.supplier?.address?.city === 'Paris': it gives false while the supplier is empty, instead of an error. Keep writing the field with {{ }} or #: supplier.address.city alone does not read the field, so the rule fails and counts as false.
  • Texts are left as written. Only {{…}} and #field are replaced: the text between quotes, the text of a template literal and regular expressions are not changed, so in {{reference}}.startsWith('#12') the '#12' stays a text. The ${…} parts of a template literal are code, so {{x}} and #x are replaced there.
  • In a loop, the row comes first. Inside a Grid with the Loop option, {{field}} or #field reads the value of the current row when field is a widget of the loop. For example, in a loop of expense lines, the condition {{amount}} > 100 on the Required rule of the receipt field makes the receipt required only on the lines above 100. A field outside the loop is read from the page.
  • Variables set later are followed. A rule can read a model variable that no widget holds and that does not exist yet when the page opens, for example {{total_amount}} set later by a setModel action: the rule is updated as soon as the variable is set.

5. Troubleshooting Common Issues in RulesDirect link to 5. Troubleshooting Common Issues in Rules

If a rule isn't working as expected, these troubleshooting steps can help you diagnose the problem.

5.1. Check the Browser's Developer ConsoleDirect link to 5.1. Check the Browser's Developer Console

This is your first and most important tool. Press F12 to open your browser's developer console and look for the message:

SoftyFlow: parts of this page are ignored because they are not valid

It is followed by the list of what is ignored (50 entries at most), each with its text as written in the builder:

  • rule "…" is not a valid expression: a rule that is not valid JavaScript (syntax mistake, a missing parenthesis…). It is ignored and counts as false.
  • text "…" is not a valid expression: a {{ }} in a title, a text, an HTML widget or an alert, or a ${ } in the source of a PDF reader. It is shown as written.

A rule that is valid but fails while it runs is not reported: it simply counts as false (see section 4.2), so check that the data it reads is loaded.

If the rule calls a function of the page's Functions script (see section 6), also look for this other message:

SoftyFlow: the page code functions does not compile, it is ignored

The whole script is then ignored: its functions do not exist, so the rules that call them fail and count as false, without any other message. The same message can name computed, watch, filters or variables.

5.2. Verify Widget Model NamesDirect link to 5.2. Verify Widget Model Names

A common slip-up is a typo in a widget's model name. Model names are case-sensitive. Double-check the Variable/Model property in the widget's Global card to ensure it exactly matches the name used between {{ }} or after # in the rule expression.

5.3. Beware of Data Type MismatchesDirect link to 5.3. Beware of Data Type Mismatches

Ensure you are comparing values of the same data type. A value from a numeric input might be a string by default. You may need to explicitly convert it to a number for a mathematical comparison.

// INCORRECT: The value '5' is a string and may not compare correctly.
{{my_numeric_field}} > 10

// CORRECT: Convert the field's value to a Number before the comparison.
Number({{my_numeric_field}}) > 10

6. Best Practices for Writing and Maintaining RulesDirect link to 6. Best Practices for Writing and Maintaining Rules

Follow these guidelines to keep your rules clean, performant, and easy to debug.

  • Keep Logic Simple and Focused: A rule should perform a single, clear check. If a condition becomes too complex, it's a sign that the logic should be refactored.
  • Abstract Complexity into Functions: For rules that require multi-step logic (e.g., checking several fields, performing calculations), move that logic into a reusable function of the page's Functions script (Code page). Your rule expression can then simply call that function (for example isOverBudget()), making it clean and readable. If such a rule always stays false, check that the script compiles (see section 5.1).
  • Optimize for Performance: Rules execute frequently as the user interacts with the form. Avoid performance-heavy operations like complex loops or heavy data processing within a rule. Pre-calculate values whenever possible.
  • Be Explicit with Data Types: As highlighted in troubleshooting, always be mindful of data types. Use Number(), String(), and other casting functions to prevent unexpected behavior from automatic type coercion.

By mastering these techniques, you can build highly adaptive and user-friendly interfaces that streamline data collection and improve the overall user experience.