3

In a Joomla 3.9.3 module, I'm trying, with no luck, to show/hide a field with showon by checking the values on other three fields

My XML:

<field
    name="foo"
    type="text"
/>
<field
    name="bar"
    type="text"
/>
<field
     name="fooimg"
    type="media"
    showon="foo!:[OR]bar!:"
/>
<field
    name="baz"
    type="radio"
    class="btn-group btn-group-yesno"
    showon="foo!:[OR]bar!:[AND]fooimg!:"
    default=""
    >
    <option value="bazval">JYES</option>
    <option value="">JNO</option>
</field>

With: showon="foo!:[OR]bar!:[AND]fooimg!:" on baz field I expect that baz is shown when (foo or bar has a value) and fooimg has a value too.

But the results are:

    foo = true 
    bar = false
    fooimage = true
    baz is NOT SHOWED (should be showed)

    foo = false
    bar = true
    fooimage = true
    baz IS SHOWED (as aspected)

With fooimage or foo and bar set to False it work as expected.

I also tried: "fooimg!:[AND]foo!:[OR]bar!:"

What did I do wrong?

0

I'm not fully sure if this can help you, but since the fooimg field is only shown when either foo or bar is true, then in baz field you do not have to check that again, so it would be enough just to check if fooimg field is true or not, thus:

<field
    name="baz"
    type="radio"
    class="btn-group btn-group-yesno"
    showon="fooimg!:"
    default=""
    >
    <option value="bazval">JYES</option>
    <option value="">JNO</option>
</field>

This baz field will only be shown if the foo or bar is not empty and fooimg is not empty. So you actually get the same result simply (that you actually wanted to get).

  • Thanks @zollie, in effect at first I designed the module like this, but its not correct, in case of the data update, there is a possibility that the values in "foo"/"bar" will be deleted, in this case, "baz" stay visible without the possibility to change fooimg, to hide baz, because its hidden. – Znort Mar 12 at 21:24
  • @Znort - in FormHelper class I do not really see the possibility to chain conditions like you tried. It looks like that the method (parseShowOnConditions()) only consider 1 OR or 1 AND as condition. – Zollie Mar 13 at 8:23
  • You right @zollie, it seems that the showon is still not well implemented, also with the combo fields has some issues. Many Thanks anyway! – Znort Mar 13 at 14:31

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.