1

So this is an example XML:

<form>
    <fieldset>
        <field name="field1" type="text" default="" label="" description="">
            <option value="">JSELECT</option>
            <option value="1">A1</option>
            <option value="2">A2</option>
        </field>
        <field name="field2" type="text" default="" label="" description="" />

        <fields name="group1">
            <field name="field11" type="text" default="" label="" description="" />
            <field name="field12" type="text" default="" label="" description="" />
        </fields>

        <fields name="group2">
            <field name="field21" showon="noidea" type="text" default="" label="" description="" />
            <field name="field22" type="text" default="" label="" description="" />
        </fields>
    </fieldset>
</form>

I'm trying to toggle field21 in group2 when changing field1.

This just adds the current group:

 <field name="field21" showon="field1:2" type="text" default="" label="" description="" /> 

creates: data-showon="[{"field":"jform[group2][field1]"

This targets another field in another group, but i need the root...

<field name="field21" showon="group1.field1:2" type="text" default="" label="" description="" />

creates: data-showon="[{"field":"jform[group1][field1]"

This was just a try

 <field name="field21" showon=".field1:2" type="text" default="" label="" description="" />

creates: data-showon="[{"field":"jform[][field1]"

This is what i need: data-showon="[{"field":"jform[field1]"

I only found a similar question here, but that was a bit different and already solved: https://github.com/joomla/joomla-cms/issues/6744

I dont see if parseShowOnConditions is solving this.

There is a pull request making this possible, but it wasnt merged into Joomla 3.22: https://github.com/joomla/joomla-cms/pull/30850

Maybe there is another way of getting this to work.

4
  • Mike, why do not you just overwrite the file as it is in the pull request, since it will come out with the next update of Joomla then your file will stay the same then. Usually it is bad to touch any core file but in this case it is a viable option. Otherwise it could be solved in few lines of code probably before rendering the fieldset for example in the template file with setting the field attribute hidden to true on a condition of the value of the other field (maybe).
    – Zollie
    Oct 10 '20 at 6:07
  • note: since the text field does not support hidden attribute thus maybe the class attribute of the field could be set to hidden for example on conditions...
    – Zollie
    Oct 10 '20 at 8:12
  • well its part of a component, that is in productive enviroments. i can't make sure everyone has the latest joomla version installed.
    – Mike
    Oct 10 '20 at 12:20
  • Ohh, I see. Then I would handle that before rendering the Form as I mentioned above.
    – Zollie
    Oct 10 '20 at 15:22

Your Answer

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

Browse other questions tagged or ask your own question.