?

User tests: Successful: Unsuccessful:

avatar chivitli
chivitli
16 Feb 2014

Overview

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.

Testing

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).

Tracker: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33295&start=0

avatar chivitli chivitli - open - 16 Feb 2014
avatar chivitli
chivitli - comment - 16 Feb 2014

Reference: #2847

avatar beat
beat - comment - 16 Feb 2014

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...

avatar chivitli
chivitli - comment - 17 Feb 2014

Using equation mark would be more confusing, IMHO, like
showon="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 :)

avatar Bakual
Bakual - comment - 17 Feb 2014

@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.

avatar Bakual
Bakual - comment - 17 Feb 2014

Updated PR is fine now. Tested successful. Thanks!

avatar chivitli
chivitli - comment - 3 Mar 2014

@Bakual

Any chance to set this to "ready to review" since there are two tests since a while? Thanks!

avatar Bakual
Bakual - comment - 3 Mar 2014

Set to RTC.

avatar chivitli
chivitli - comment - 3 Mar 2014

Thanks!

avatar infograf768
infograf768 - comment - 26 Mar 2014

Has'nt this be committed in
ROOT/layouts/joomla/content/options_default.php

avatar chivitli
chivitli - comment - 26 Mar 2014

This is the same feature, but made available for extensions like plugins and modules, in a similar way like Bakual made it available for components. Check comments at #1240

avatar infograf768
infograf768 - comment - 26 Mar 2014

I suggest you update therefore your PR as it can't be merged.
Also, we now use renderField() instead of getControlGroup

avatar chivitli
chivitli - comment - 26 Mar 2014

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

avatar infograf768
infograf768 - comment - 27 Mar 2014

I changed the status of the tracker from RTC to In Progress in the meanwhile

avatar chivitli chivitli - change - 27 Mar 2014
Labels
avatar chivitli chivitli - change - 27 Mar 2014
Title
Adding the "showon" feature to JForm
[#33295] Adding the "showon" feature to JForm
avatar chivitli chivitli - change - 27 Mar 2014
Title
Adding the "showon" feature to JForm
[#33295] Adding the "showon" feature to JForm
avatar chivitli chivitli - reference | - 27 Mar 14
avatar chivitli
chivitli - comment - 27 Mar 2014

I made a new PR (as I couldn't get this one synced properly). Please check #3379

avatar chivitli chivitli - change - 27 Mar 2014
Status New Closed
Closed_Date 0000-00-00 00:00:00 2014-03-27 16:02:00
Labels
avatar chivitli chivitli - close - 27 Mar 2014
avatar chivitli chivitli - close - 27 Mar 2014
avatar hkraskian
hkraskian - comment - 24 Jan 2015

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.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3127.
avatar hkraskian hkraskian - test_item - 24 Jan 2015 - Tested unsuccessfully
avatar Oxonium
Oxonium - comment - 19 Feb 2015

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 !


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/3127.
avatar Oxonium Oxonium - test_item - 19 Feb 2015 - Tested unsuccessfully
avatar Bakual
Bakual - comment - 19 Feb 2015

I don't think the user profile uses a regular JForm, so it will not work there.

avatar Oxonium
Oxonium - comment - 19 Feb 2015

Damn, thanks for the heads up.

Any chance to do conditional fields in Joomla registration form another way (beside specific JS rules) ?

avatar Bakual
Bakual - comment - 19 Feb 2015

Not that I'm aware of. Best bet is to use custom JS there I think.

avatar Oxonium
Oxonium - comment - 19 Feb 2015

Let's do this then. Thanks for answering ;)

Add a Comment

Login with GitHub to post a comment