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>        
  • @Lodder Thank you for making it look a lot better! – Henny Smafter Mar 1 '16 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 Mar 1 '16 at 19:02
  • Oke. Thank you for that tip! Do you think that this should be added though? – Henny Smafter Mar 1 '16 at 19:27
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
    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. – Henny Smafter Nov 10 '16 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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