1

I have tried the following exact example in the Joomla documentation:

Showon attribute for list options

<field
    name="fielda"
    type="list"
    label="FIELDA_LABEL"
    description="FIELDA_DESC"
    >
    <option value="editor">TYPE_EDITOR</option>
    <option value="text">TYPE_TEXT</option>
    <option value="textarea">TYPE_TEXTAREA</option>
</field>

<field
    name="fieldb"
    type="list"
    label="FIELDB_LABEL"
    description="FIELDB_DESC"
    >
    <option value="0">JNO</option>
    <option value="1">Option 1</option>
    <option
        showon="fielda:text,textarea"
        value="2">Option 2</option>
    <option
        showon="fielda:text"
        value="3">Option 3</option>
</field>

I rendered the fields with the code:

<?php echo $this->form->renderField('fielda'); ?>
<?php echo $this->form->renderField('fieldb'); ?>

In the documentation it says:

Since Joomla 3.9.0 one can use the showon attribute for option tags in a list field.

But I'm trying in Joomla 4 and seems it doesn't work. All options in fieldb, appear with any option of fielda

Does Showon attribute for list options work with Joomla 4 ?

1 Answer 1

2

Finally I manage to get this working in my component.

I needed to add the javascript in the layout, like this:

$wa = $this->document->getWebAssetManager();
$wa->useScript('showon');
1
  • Looks like this is not working for groupedlist options :(
    – maidan
    Mar 14 at 12:16

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.