User tests: Successful: Unsuccessful:
By means of the new field attribute "renderon" you can make a field dependent upon any global setting or any setting with any component much the same way as the attribute "showon" does for other fields in the same form. The syntax in the "renderon" attribute is identical to the syntax in the "showon" attribute with the following modification: you have to add either the string "global" or the name of a component followed by a colon at the beginning of each check.
You might add this new attribute to any field in any form where this field shall only be shown in this form if one or more global settings and/or component settings have distinct values.
In order to test this PR you have to change a field definition in any form and make this field dependant upon one or more global settings and/or component settings (no such change is currently part of this PR).
For the following test you need a Joomla installation that is reachable both via HTTP and HTTPS.
A candidate I can suggest is the form in modules/mod_login/mod_login.xml
. Change the definition of the "usesecure" field as follows:
<field
name="usesecure"
type="radio"
label="MOD_LOGIN_FIELD_USESECURE_LABEL"
description="MOD_LOGIN_FIELD_USESECURE_DESC"
class="btn-group btn-group-yesno"
default="0"
renderon="global:force_ssl:0,1"
>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
The line starting with "renderon=" is the new line in this definition, I made no other changes here.
Next go to the global configuration and check that the "Force HTTPS" setting is either "None" or "Administrator Only". If the setting is "Entire Site" change it accordingly.
Next go to "Extensions" => "Modules" and search for all site modules containing "login" in their names (with the basic examples installed you should have three such modules).
Open one of these modules and check that the field "Encrypt Login Form" exists (second but last at the "Module" tab). Close this module.
Next go again to the global configuration and set the "Force HTTPS" setting to "Entire Site".
Return to "Extensions" => "Modules" and reopen the module you checked before. The field "Encrypt Login Form" shall no longer exist. Close this module.
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
Category | ⇒ | Fields Libraries |
Title |
|
Title |
|
thanks @ggppdk for your excellent suggestion!
I just changed my PR according to the code you suggested, moreover I changed the title, the change summary and the testing instructions.
i think this is very usefull thanks.
just one remark. i think this behaviour should be integrated in the current showon
, not in a new attribute.
I wonder if that is such a great idea for core.
The showon
feature was introduced to have a way of dynamically showing/hiding certain parts of the current form depending on parameters being changed at runtime. Eg a user enables one parameter and gets some related options instantely without reloading the form.
In the proposed case here it is different as the value will not change after the form is loaded. This is done solely at loadtime here.
At the same time this feature here could already be easily done with a custom formfield.
This would also encourage coupling between components. What's the use-case?
This would also encourage coupling between components.
This help in reduce configuration options. If we display all of the fields, then the coupling will be less because we display all of them ?
What if we remove the ability for components and only allow this attribute to use global config ?
is it more acceptable ?
What's the use-case?
This helps configuration UI be less clattered, and hide fields that are not used during configuration (ok i know you meant usage in core configuration, but this will be mostly useful to 3rd party extensions)
At the same time this feature here could already be easily done with a custom formfield.
you mean
is making configuration simpler for the user a good purpose ?
this a trade-off, maybe it is not worth having,
still it feels like a natural extension of showon capabilities
My initial motive for this PR was to have a possibility for disabling the "usesecure" field in the mod_login
module: this field is useless and probably misleading if you set "Force HTTPS" in the global configuration to "Entire Site". @conconnl suggested in the discussion about my PR #8619 that we should have a way to gray out or hide that "usesecure" field if the entire site is shown via HTTPS. Neither he nor I know about any other way to achieve this currently, so I implemented the new field attribute "showon_ext" (which I initially called "globalshowon" since it only coupled a form field with one or more global configuration items). Thanks to the suggestion of @ggppdk I enhanced this such that you can now couple a form field with global configuration items and/or configuration items of any component.
if it already known that this field should be disabled because globalOption = blabla
, then why need to render this field at all?
I do not see a reason to use original showon
here. Just do not render the field.
(btw "showon" not fastest script on the page when you have a loot fields in the form)
Yes this is the intention of "showon_ext": the field will not be part of
the form since there is no way to make it visible by changing any other
field in the form (in other words: the field is not rendered if the
conditions given in "showon_ext" evaluate to false).
Am 21.07.2016 um 09:57 schrieb Fedir Zinchuk:
if it already known that this field should be disabled because
|globalOption = blabla|, then why need to render this field at all?? I do not see a reason to use original |showon| here. Just do not render
the field.
(btw "showon" not fastest script on the page when you have a loot fields
in the form)—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#11207 (comment), or
mute the thread
https://github.com/notifications/unsubscribe-auth/AH9KbRJuTL8qa1veIQudU43YO_R_TAcsks5qXyZUgaJpZM4JP-D_.
Am I correct that this can be used in a menu item options to show a field or not based on the components global options? If so then this would be very useful as we can greatly simplify the display of options in a menu item in the same way as I did for component options in an earlier PR
I do not see a reason to use original showon here. Just do not render the field.
you are right , this PR does what you say,
it does not hide it, or disable it, instead it does not render it at all, see line:
https://github.com/joomla/joomla-cms/pull/11207/files#diff-9d799c43096f42c965b28c44a8d8a8b1R988
@jo-sf
i think the attribute name 'showon_ext' is confusing / wrong,
attribute name should be 'renderon':
renderon="..."
Title |
|
Title |
|
@brianteeman
Yes, you are correct, the intention of this PR is to be able to not render form fields at all if they are useless due to global settings or settings within any component.
@ggppdk
I agree with you that the attribute name "showon_ext" is misleading since there is no way for the user of a form to make a field visible that is hidden due to e.g. any global setting (at least not by changing any other field in the same form as is the case with the "showon" attribute). The attribute name "renderon" matches what really happens: if the conditions given evaluate to True the field will be rendered, otherwise the field will not be rendered.
I therefore renamed the attribute to "renderon" and changed the initial comment including testing instructions accordingly.
This feature makes much sense,
into simplifying forms,
just one using it should not mark such depedent fields as e.g. required,
or otherwise the server-side validation should made aware of the renderon="..."
and avoid throwing an error
About the above, see similar discussion here:
#11243
Regarding the example form I used in my test instructions it shall be discussed whether the condition "global:force_ssl:0,1" is suitable. It is clear that showing the "Encrypt Login Form" field is useless if "Force HTTPS" is set to "Entire Site" (numeric value: 2). It is also clear that the "Encrypt Login Form" shall be shown if "Force HTTPS" is set to "Administrator Only" (numeric value: 1).
But what about the setting "None" (numeric value: 0)? In this case there is probably no server certificate for HTTPS available, otherwise I would assume that the administrator of the Joomla installation would have set "Force HTTPS" to "Administrator Only" (at least). IMO it makes no sense (from the security point of view) to let the user of a site log in via HTTPS whereas the user of the backend logs in via HTTP.
And at least currently there is no check whether HTTPS is available if the "Encrypt Login Form" field is set to "Yes" as is the case for the "Force HTTPS" field when changing it from "None" to any other value.
So my proposal regarding the "Force HTTPS" configuration is as follows:
This is nothing to be added to this PR, instead it shall be considered when this PR has been accepted and the new feature is to be used e.g. in the mod_login
module.
Applying my proposal to the test case given above would mean, that the attribute "renderon" should be set as follows:
renderon="global:force_ssl:1"
Doing so the "usesecure" field ("Encrypt Login Form" field) will be shown only if the global configuration field "Force HTTPS" is set to "Administrator Only" (numeric value: 1).
I have tested this item
I have tested this item
I have tested this item
I have asked the PLT whether or not we should include this feature into the core.
Rel_Number | 0 | ⇒ | 12518 |
Relation Type | ⇒ | Related to |
Status | Pending | ⇒ | Needs Review |
What's the status here?
Status | Needs Review | ⇒ | Information Required |
@mbabker @franz-wohlkoenig
Do you need any information from my side? Or is it about adding this feature to the core or not?
IMO this feature makes sense in that it allows to simplify forms and to hide fields that are unnecessary and probably misleading due to settings in another form, e.g. in the global configuration or even in another component. The only point to consider when adding this attribute to any form field is that this field must not be required - see also the comment from @ggppdk (23 Jul 2016).
Well, it hasn't been touched in 6 months either and currently has merge conflicts. So if this is something being pursued it needs to be updated and get a fresh round of testing and review, otherwise it can be closed out.
@mbabker
Thanks for your feedback. Some minutes ago I merged my PR with upstream/staging and thus removed the merge conflict. In doing so I also adapted my PR to the general changes made in field.php in that all field attributes are now instance attributes and that the parsing of the "renderon" conditions is now done by a new method in helper.php as is the case with the parsing of the "showon" conditions.
I hope that testing this PR will work without any problems - my own tests were successful.
I have tested this item
Status | Information Required | ⇒ | Discussion |
@franz-wohlkoenig yes, the test instructions are still the same - but as I saw right now my PR is again out-of-date (just three days ago I merged it with upstream/staging).
its not really a problem for the base branches to be out of date. its only a problem if there is a merge conflict
@brianteeman thanks for your notice, but when I saw it I had already merged my PR with staging...
Status | Discussion | ⇒ | Information Required |
@jo-sf how to go on with this PR?
@franz-wohlkoenig actually I don't know how to proceed with this PR. It seems as if there is currently no great need for such a feature, but when I can continue one day with the secure login topic
(I probably missed some of my issues now) the "renderon" feature would be of some help since it can be used to hide fields in the configuration that are not needed due to the setting of other fields. Well one simple example for using that feature I've already given in the test instructions for this PR - IMO it makes no sense to enable secure login in any mod_login module as long as no HTTPS is available (there is a test in the backend such that you cannot switch to HTTPS unless you have HTTPS available but no such test is done when changing the mod_login setting).
Maybe there are some other places when configuring modules or components where a dependency between any global configuration item and a configuration item for that module or component exists. Any such suggestions are welcome!
Status | Information Required | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2017-08-03 14:47:08 |
Closed_By | ⇒ | franz-wohlkoenig |
Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/11207
closed as stated above. It can always reopen if needed.
What a shame this is closed. It would be really useful to me right now. Use case exactly as stated in one of the comments above - to hide a menu item setting if a global setting has disabled it.
In particular I have a global setting with three possible values: 0=hide, 1=show, 2=show & link
In the menu I only want to display the option if the global setting is >0 and to have three options: ''=use global, 1=show, 2=show & link
In other words I want a global setting to turn off the ability to override it at the menu level. But if the global setting is on (1 or 2) then I want the menu to have the option of using the global setting or overiding it to 2 or 1.
I suppose I could implement it as a custom field, but this is not the first time I have wished for this logic and it seems like core functionality to me.
Bring back "renderon" !
With a little more work, this could be more flexible to support any component parameters,
Examples
...
Sample code