11

I have 3 fields defined in my XML file like so:

<field name="field1" type="radio" label="Field 1" class="btn-group" default="1">
    <option value="1">JYES</option>
    <option value="0">JNO</option>
</field>

<field name="field2" type="radio" label="Field 2" class="btn-group" default="1">
    <option value="1">JYES</option>
    <option value="0">JNO</option>
</field>

<field name="field3" type="radio" label="Field 3" class="btn-group" default="1">
    <option value="1">JYES</option>
    <option value="0">JNO</option>
</field>

Now what I'd like to do is only show field3 if field1 and field2 are set to 1.

1 Answer 1

19

You can chain the attribute values of showon, using [AND], like so:

showon="field1:1[AND]field2:1"

Adding more fields to the chain is also allowed.

On a side note, you can use an [OR] clause in the chain too, adding more complexity, for example:

showon="field1:1[AND]field2:1[OR]fieldX:1"

Update for Joomla 3.7:

As of Joomla 3.7, you will be able to to use the ! operator (not equal to):

showon="field1!:1"

This means, if field1 does not equal 1

10
  • Is there a not equal to option for showon?
    – CoalaWeb
    Feb 10, 2017 at 16:02
  • @CoalaWeb - That's what it's already doing. field1:1 means field1 == 1
    – Lodder
    Feb 10, 2017 at 16:05
  • I'm looking for a != option for large/dynamic select lists that only have one option that would hide another form field rather than a large comma separated list. From my research it doesn't look like this exist I might look into a pull request, Cheers.
    – CoalaWeb
    Feb 11, 2017 at 0:33
  • can you use !empty or !:* ?
    – Eoin
    Jun 19, 2017 at 14:57
  • 1
    Apparently you can use showon="foo!:" I am yet to test. See here: joomla.stackexchange.com/questions/21022/form-field-showonempty
    – Eoin
    Jun 28, 2017 at 11:26

Your Answer

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

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