Conditional Label

  • 1
  • Question
  • Updated 3 years ago
Is there a way I can change the field labels depending on a condition?
Photo of Jackie I

Jackie I

  • 70 Points

Posted 3 years ago

  • 1
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,756 Points 10k badge 2x thumb
Not directly that I know of......however, you can display the same field multiple times on your page and change the label on each field. You could then conditionally render the fields so that one displays when one condition is met and the other displays if the other condition is met. You can also make one required and one not.
Photo of Bill McCullough

Bill McCullough, Champion

  • 13,250 Points 10k badge 2x thumb
The labels support merge syntax.  You can use {{#fieldname}}label{{/fieldname}} to show hide depending upon whether the field 'fieldname' has a value.  Try using a model UI formula field of type 'checkbox' to handle the show/hide.
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,266 Points 10k badge 2x thumb
One thing to note here when using merge syntax is that Skuid does not currently update label text when data changes that would effect the label text itself change (see  ).  For example, if the label itself is dynamic based on another field value, the label text won't change as the other field changes.

If you do not need to change the label as data changes in the model, the merge syntax will work perfectly.  If you do need to change the label as data changes, you have two options:

1) Use the approach Raymond outlined 
2) Write a custom field renderer that takes ownership of building the label element replacing the elements that Skuid emits.  In this renderer, you would need to register for events and respond by updating the label text.  The easiest approach here is to build the label using the skuid.ui.TemplateComponent.  If you head down this path, be aware of the issue at  This issue will make things rather difficult but there are creative ways to solve for it (none of which are really good options however).

Another thing to note is that merge syntax is not processed when defined on the model itself (field metadata override), only when it's specified at the component field level.  See for more info.

FYI - All of these issues are on Skuid's backlog to address, timing of the fixes are unknown however.