Is there a way I can change the field labels depending on a condition?
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.
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.
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 https://community.skuid.com/t/field-editor-labels-built-using-merge-syntax-do-not-upda… ). 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 https://community.skuid.com/t/obtain-label-metadata-property-of-field-in-renderer?rfm=…. 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 https://community.skuid.com/t/merge-syntax-not-processed-when-overriding-label-on-mode… for more info.
FYI - All of these issues are on Skuid’s backlog to address, timing of the fixes are unknown however.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.