5

I am trying to figure out how to get the showon tag to work with nested fields. Could someone please look at the code below and tell me what I do wrong or if it is at all possible.

<field name="main"
       type="radio"
       class="btn-group btn-group-yesno"
       default="0"
       label="LABEL"
       description="DESC" >
       <option value="0">JNO</option>
       <option value="1">JYES</option>
</field>

<field name="sub"
       type="radio"
       class="btn-group btn-group-yesno"
       default="0"
       showon="main:1"
       label="LABEL"
       description="DESC">
       <option value="0">JNO</option>
       <option value="1">JYES</option>
</field>        

<field name="nested"
       type="text"
       default=""
       showon="main:1,sub:1"
       label="LABEL"
       description="DESC">
</field>        
3
  • @Lodder Thank you for making it look a lot better! Commented Mar 1, 2016 at 18:53
  • I don't think multiple values on the showon attribute is possible. You'll have to create a custom form field and inject some JS to do this
    – Lodder
    Commented Mar 1, 2016 at 19:02
  • Oke. Thank you for that tip! Do you think that this should be added though? Commented Mar 1, 2016 at 19:27

1 Answer 1

3

Man, although I'm not 100% sure, you should use:

<field name="nested"
       type="text"
       default=""
       showon="main:1[AND]sub:1"
       label="LABEL"
       description="DESC">
</field>

The [AND] expects both to be true. This way your nested field should work.

1
  • 1
    Yeah you are right. The thing though is that when I asked the [AND] and the [OR] function did not yet existed. But upvoting and selecting your answer as the best as it is nowadays correct and quite frankly essential. Commented Nov 10, 2016 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.