User tests: Successful: Unsuccessful:
In the Joomla Global Configuration we use showon attribute to show/hide certain fields based on the state of a "parent" field. You can see this for example with the FTP settings where the settings itself only show when "Enable FTP" is set to "Yes". It's also available for Component settings.
This PR takes this feature to the JForm so it can be used in any xml file.
You can add a showon attribute to any config field you want to hide. For example in
modules\mod_finder\mod_finder.xml you add to line 94
showon="show_label:1". So it looks like this:
<field
name="label_pos"
type="list"
default="left"
showon="show_label:1"
label="MOD_FINDER_FIELDSET_ADVANCED_LABEL_POS_LABEL"
description="MOD_FINDER_FIELDSET_ADVANCED_LABEL_POS_DESCRIPTION">
<option
value="right">JGLOBAL_RIGHT</option>
<option
value="left">JGLOBAL_LEFT</option>
<option
value="top">MOD_FINDER_CONFIG_OPTION_TOP</option>
<option
value="bottom">MOD_FINDER_CONFIG_OPTION_BOTTOM</option>
</field>
This will only show the "Label position" setting only if the "Show Label" is set to "Yes" (which has the value 1).
Imho, the syntax chosen ( showon="show_label:1" ) is not very semantic nor developer-friendly...
Is ":" meaning "=" ? then why not use "=" ? in that case you could use > and so on...
Using equation mark would be more confusing, IMHO, likeshowon="field=1"
. I would keep equation only for attribute key -> value, not reuse it again inside of the value. Also, it's consistent with usage in Component parameters, if we change it here we should change it there too, but that would break BC now that it was already merged :)
@beat Since the feature already exists, we have to use the syntax already present. > and < comparisions would not work with current JS anyway.
The way it works is that you can give a comma separated list of values which should match. Like showon="parentfield:1,2"
would show the childfield if the parentfield has the value 1 or 2.
Updated PR is fine now. Tested successful. Thanks!
Set to RTC.
Thanks!
Has'nt this be committed in
ROOT/layouts/joomla/content/options_default.php
I suggest you update therefore your PR as it can't be merged.
Also, we now use renderField() instead of getControlGroup
Oh wait, I see now, this PR is not valid anymore with the latest changes, the layout file is layouts/joomla/form/renderfield.php, the one you mentioned is another PR. I have to check if this works with the latest changes, or I have to make a new PR
I changed the status of the tracker from RTC to In Progress in the meanwhile
Labels |
Title |
|
Title |
|
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-03-27 16:02:00 |
Labels |
I tried showon in a copy of user profile plugin.
There are two xml files, one for administrator, the other one for registration and profile editing.
The first one is in /plugins/user/profile5/ with name of profile5.xml
The second one is in /plugins/user/profile5/profiles with name of profile.xml.
showon works correct in first file. but doesn't work in second file.
Same as @hkraskian here. I am trying to use this feature in a custom profile plugin and it is not working.
Anyone has an idea to make this work ?
Thanks a lot in advance !
I don't think the user profile uses a regular JForm, so it will not work there.
Damn, thanks for the heads up.
Any chance to do conditional fields in Joomla registration form another way (beside specific JS rules) ?
Not that I'm aware of. Best bet is to use custom JS there I think.
Let's do this then. Thanks for answering ;)
Reference: #2847