How to use dependent() to hide/show multiple "presets" of editor fields

How to use dependent() to hide/show multiple "presets" of editor fields

d00mboyd00mboy Posts: 10Questions: 5Answers: 0

The dependent() examples related to showing/hiding fields in editor (i.e., Simple/Detailed view) based on the value of another editor field are clear and work fine for me, but only allows two "views", hiding and showing a single array of fields.

I would like to show/hide multiple sets of fields, depending on which of several checkbox values is set in the dependent field. So instead of "Simple or Detailed", something like "Simple", "Medium", or "Detailed", each with different sets of fields hidden/shown. In the dataTable part, I can do this with colvisGroup buttons, and I want to have more-or-less corresponding sets of fields available in the editor view.

Is this possible? I don't have a specific code problem to sort out, I just don't get how to make the dependent function loop thru multiple possible values (of the checkbox) and show/hide different fields based on each value, instead of just checking against a single value (i.e., 'Simple'). I'm not very experienced with js and mostly just adapt from example code but can't find an example showing how to accomplish this.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599
    Answer ✓

    Yep, that's definitely possible, you can have multiple dependent() actions on the form, and you can even have click triggers that just call hide() and show() instead, so different routes you can go with the code.

    This thread here shows how multiple dependents() can be set, and alternative approaches that may be better suited,

    Colin

  • d00mboyd00mboy Posts: 10Questions: 5Answers: 0

    Thank you! -- in particular looking at the hide() and show() API examples you suggested helped it all click, even though I still ended up using dependent(). I was able to just use simple if else statements to check against each checkbox option.

This discussion has been closed.