I created these fields in my custom module backend as below :
<field name="show_option" type="radio" default="0" label="Radio" description="Desc" class="btn-group btn-group-yesno">
<option value="0">Hide</option>
<option value="1">Show</option>
</field>
<field name="option_name" type="text" default="0" label="Text" description="Desc" showon="show_option:1"/>`
When I choose 'show_option' to 'Show' the 'option_name' field will automatically be shown under the radio field.
The 'option_name' field will only be shown after I save the form.
Joomla 4.0.0-beta1-dev.
And please provide some system information. Right now we don't even know if this issue is for Joomla 3 or 4.
In Both Joomla 3 and 4 showon works in Global Configuration in backend. But the buttons are not HTML elements <field>
, they are <input>
.
Strange - but I have the same issue in J4, developing a new component.
The field definition works if I add it into the com_config/forms/application.xml,
but not in my own component where I wanted to use it in a edit form.
I use class="switcher" in J4.
<field name="show_jury"
type="radio"
default="1"
label="xx"
class="switcher"
>
<option value="0">Hide</option>
<option value="1">Show</option>
</field>
<field
name="jury"
type="text"
label="yy"
showon="show_jury:1"
/>
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/27555.
showon works fine in J3 with btngroup. I've suspected issues in J4 however
I'm sorry I forgot to include the system information. It's Joomla 4.0.0-alpha12
Labels |
Added:
J4 Issue
|
please use the nigthly builds https://developer.joomla.org/nightly-builds.html or the current 4.0-dev branch as alpha12 is quite old (oct 2019)
<field
name="show_associations"
type="radio"
label="JGLOBAL_SHOW_ASSOCIATIONS_LABEL"
class="switcher"
default="0"
>
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
</field>
<field
name="flags"
type="radio"
label="JGLOBAL_SHOW_FLAG_LABEL"
class="switcher"
default="1"
showon="show_associations:1"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
works perfectly in articles config.
Works also fine in Language Switcher module.
Can you try if it works without the class "btn-group" and "btn-grp-yesno"? Because I have a feeling it's related to that btn-grp stuff and not to the showon feature itself.
I have updated my installation to 4.0.0-beta1-dev.
It works by using class="switcher" instead of class="btn-group btn-group-yesno". Is this the expected behavior?
Yes
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-01-24 03:41:17 |
Closed_By | ⇒ | Quy |
yup, showon doesn't work withclass="btn-group btn-group-yesno"
, but it works with class="switcher"
Title |
|
The class btn-group-yesno
does not exist anymore in J4 as a lot of other stuff which are now obsolete.
I agree that docs should be updated, but there is no reason imho to re-open this Issue.
The class btn-group-yesno does not exist anymore in J4 as a lot of other stuff which are now obsolete.
That's not true. btn-group-yesno
works perfectly fine in J4.
And obviously, that should work with showon as well.
I'm reopening this issue.
Status | Closed | ⇒ | New |
Closed_Date | 2020-01-24 03:41:17 | ⇒ | |
Closed_By | Quy | ⇒ |
Code is here:
joomla-cms/layouts/joomla/form/field/radio/buttons.php
Lines 44 to 45 in 64b9025
The styling itself uses regular features from Bootstrap. So you will not find that class in the CSS rules.
The issue isn't related to the btn-group-yesno
itself. It's related to the generic btn-group
which is a regular feature from Bootstrap. So the showon JS code needs to take care of that I guess.
Status | New | ⇒ | Confirmed |
It's just Bootsrap's data-toggle
that's causing the issue.
Simply add:
elem.addEventListener('click', () => { self.linkedOptions(key); });
in here:
https://github.com/joomla/joomla-cms/blob/4.0-dev/build/media_source/system/js/showon.es6.js#L100
(part of the) issue is also that showon.js functionality is only loaded when the 'switcher' is created via a layout file set on the config parameter (layout="joomla.form.field.radio.switcher").
So manually setting the switcher class to your radio button will not work as the showon functionality (js) is not loaded / initialized on that radio button.
this breaks B/C for this functionality as adding that layout parameter to radio buttons will make it work in J4, but will break the complete configuration form in J3.
@C-Lodder tried your solution but that didn't do the trick :(
I can reproduce this issue on the released Joomla! 4.0 Beta 1.
This is indeed a release blocker because it's impossible to deliver different classes in the <config>
section of a plugin, for example, depending on whether it runs under Joomla 3 or 4. As a 3PD my options are:
At this point I have to remove showon
since it's the least problematic option but it still feel like I have to choose between cutting off a finger, my arm or my head.
@C-Lodder looks good! Maybe do a PR for that change?
I didn't dive into the j4 dev environment, not a huge fan of building before I can test something. Will try to redo the change and test again. Had been trying a lot of things to find the root cause so probably messed up the installation :(
Okay, just tested change proposed by @C-Lodder again against a fresh installation and can confirm that this now works.
So the showon state of fields can now be toggled with radio field with class "switcher btn-group btn-group-yesno". So the same field config now works in both J3.9 as well as in J4.
@C-Lodder what is currently holding you back to create a PR for this? Do you expect any side effects? If you want I can create the PR for you. Just say the word :)
Sure, go for it ;)
Labels |
Added:
?
|
Added a release blocker tag tag
Sure, go for it ;)
Went for it :)
Closing as PR was merged
Status | Confirmed | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-06-06 21:14:48 |
Closed_By | ⇒ | wilsonge |
Labels |
Removed:
?
|
Can you try if it works without the class "btn-group" and "btn-grp-yesno"? Because I have a feeling it's related to that btn-grp stuff and not to the showon feature itself.