Text Element depending on field value

Heyho,

a small modeling question. Is it possible to link a form model text element with a condition regarding a field in a way, that i can show or hide the text element depending on the value of the field

The text element would be in a control grid. You could model a boolean field, calculcated with the condition of your choosing and then use the value of that boolean to show the control grid with the text element or not.

Hey @tjorben-atomic-moss :slight_smile:

Yes, this is possible. But you need to consider a specific modeling solution.

You have a Form Model which is looking like this:

The Text is in a separate Control Grid “Textfield”, while the Confirm Field is in the Control Grid “Test_Controls.”. Now you can open the Confirm field “OldEnough” and find the Dependencies.

Here you can set the Dependent Controls. If you now choose for the Value “True” the Control Grid “Textfield” this Control Grid is only shown if the Confirm is true.

The Problem you might have, is that you don’t want to show the controlling field within the Form. Then you need some custom code to hide the controlling field. This is already solved in some projects with annotations.

I hope this is helpfull!

Just a few notes to @svenja-still-dawn’s answer

Control dependencies can be set for Controls that:

  • reference an Enumeration, Boolean or Confirm Field
  • are modeled on the same Screen as the Control Grid or Section you want to show/hide
  • are not in the Control Grid or Section you want to show/hide

That means that either need to select the Field Type carefully or use a computed helper Field.

You can hide the Field using a Utility Class from the Widgets showcase. I should warn you that the Utility Classes are not end to end tested but in your case it should work. You just need to add it to your model as a Style.

So you need to:

  1. Ensure your Trigger Field is an Enumeration, Boolean or Confirm Field
  2. (Optional) Model a Computed Helper Field to convert the Field
  3. Add the Field to the Form Model by dragging and dropping it on the Screen where you want the warning
  4. Add the Warning to a Row in a Control Grid
  5. Click on your Trigger Control
  6. Edit the Dependency
  7. Add the Control Grid containing the Warning to the Trigger value for the condition when it is shown
  8. (Optional) Hide the Control using a Style
  9. (Optional) Add the Style from the Widgets showcase to the Form Model Settings
  10. (Optional) Edit the Trigger Control and select the Style that you just added at the bottom of the control editor

Here are some 2024.06 models showing you that.
ShowWarning_DM.json (3.4 KB)
ShowWarning_FM.json (5.5 KB)

From 2024.06-ext4 you can also specify that the computations and dependnecies are evaluated when you open the Form. This is done in the pre-processing settings of the Form Model.