User tests: Successful: Unsuccessful:
This is a follow up on discussions with users who needed the functionality and with Guido @degobbis who provided a widely used plugin which adds the functionality to the content and user contexts.
The showon attribute is used in forms to allow 'conditional fields' functionality.
A field can be shown or hidden depending on another field's values.
Although available, this functionality does not exist out of the box for custom fields.
This PR adds a new parameter to the form section of the options tab in custom field forms.
It works for any context, subforms and third-party custom fields.
Create a custom field of type 'list'. Call it 'List of items'. The field name should read 'list-of-items' once saved.
Add list values (text/value): None/none, Value 1/value1, Value 2/value2, Value 3/value3.
Create a second custom field of type 'Text'. Call it 'Conditional text'.
In the 'options' tab, in the 'form options' section, go to the 'Showon Attribute' parameter.
Enter: list-of-items:value1[OR]list-of-items:value2
Now go edit an article and look for the 'List of items' field in the 'Fields' tab.
The text field 'Conditional text' should only show when the list values of 'List of items' are Value 1 or Value 2.
This also works in subforms. However, fields found in subforms are 'renamed'.
When adding the previously created field 'List of items' to a subform, it shows as field[ID] (where ID is the id of the field), not as 'list-of-items'.
Therefore, when using 'List of items' and 'Conditional text' in a subform, the showon attribute for 'Conditional text' will be:
field36:value1[OR]field36:value2 where 36 is whatever ID the field 'List of items' has in the administrator console.
All fields show on a form (by default, unless some other parameter have been set).
Fields are shown conditionally, depending on the values set in other fields.
Unexpected results:
This solution works well for custom fields in forms, when conditional fields are needed.
However, in this solution, nothing prevents field values to show when displayed, even though they could have been hidden in the forms. In some cases, hidden fields should also be hidden in outputs. If anyone has any idea how this could be dealt with, please discuss your solution here. Thank you!
The syntax is already fully documented at https://docs.joomla.org/Form_field#Common_attributes.
It could also be appropriate to have a specific section where custom field creation is documented.
It needs some additions for the subform cases.
Please select:
Documentation link for docs.joomla.org: [<link>]
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
Status | New | ⇒ | Pending |
Category | ⇒ | Administration com_fields Language & Strings |
A developer would understand that option, but a user not. I'm not sure if we should expose such a technical attribute to the UI.
I do agree, I thought about it as well. How can we offer such functionality then? @degobbis plugin works but is limited to a few contexts. What if offered as a functionality that can be turned on/off?
@obuisard For the "Unexpected results" I think about the implementation in the component the problem in the frontend can not be solved.
As you must have noticed in my plugin, I also edit the content before output to remove the hidden fields by using the events.
For the user fields, even a different workaround is needed.
In my opinion, the best way to solve them is to use a plugin as I do.
@obuisard For the "Unexpected results" I think about the implementation in the component the problem in the frontend can not be solved.
As you must have noticed in my plugin, I also edit the content before output to remove the hidden fields by using the events.
For the user fields, even a different workaround is needed.
In my opinion, the best way to solve them is to use a plugin as I do.
Thank you, Guido.
It may be the way to go indeed. However, I am going to look further to see if the existing plugins we already have could be enough to avoid adding another one.
Not everything have to be a beginner feature, we have so many settings a user can't understand but a integrator can use. This field would be really help full and basically the functionality is in joomla already only the field is missing.
Labels |
Added:
Language Change
Documentation Required
PR-4.3-dev
|
Thjis works great and is a much needed feature. It is a bit technical for most users but as long as its documented its fine. Agree 100% with @HLeithner
I have tested this item
I have tested this item
Is there a way to get the showon to work in subforms without altering the field name?
Use case: fields can be both standalone and in subforms.
Status | Pending | ⇒ | Ready to Commit |
RTC
Is there a way to get the showon to work in subforms without altering the field name?
Use case: fields can be both standalone and in subforms.
Unfortunately, that is the way subforms are saved: using field ids and not field names. A change would be B/C for all subforms created to date.
Thank you Brian @brianteeman and Nicola @alikon for testing this PR!
Is there now a solution for the output in the frontend?
Documentation created at https://docs.joomla.org/Help4.x:Fields:_Edit
This also works in subforms. However, fields found in subforms are 'renamed'.
When adding the previously created field 'List of items' to a subform, it shows as field[ID] (where ID is the id of the field), not as 'list-of-items'.
Therefore, when using 'List of items' and 'Conditional text' in a subform, the showon attribute for 'Conditional text' will be:
field36:value1[OR]field36:value2 where 36 is whatever ID the field 'List of items' has in the administrator console.
Super Carlos @carlitorweb ! However, we probably should mention the specific case when dealing with showon
in subforms, where the field id is used, not the field name.
Is there now a solution for the output in the frontend?
Nobody came forward with a solution at this time.
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-01-12 15:15:54 |
Closed_By | ⇒ | HLeithner | |
Labels |
Added:
?
|
hello
Is there now a solution for the output in the frontend?
Nobody came forward with a solution at this time.
unless I'm wrong.
There is a solution that could be integrated https://github.com/nikosdion/plg_content_fieldsshowon ;-)
Unless I am doing something the wrong way or missing something out, the conditional fields do not work for me on subforms (clean J!4.3 installation). Here are the steps and screenshots:
"Conditional Text" has the following Showon Attribute: field7:value1
"Conditional Image" has the following Showon Attribute: field7:value2
Upon editing an article, the "Conditional Fields" do not appear after selecting the corresponding List Values - it works though if not inside a Subform!
Any idea?
@olivdee Yes, the current implementation in Joomla does not work for subform fields. You should instead use https://www.dionysopoulos.me/software-tools/plg_content_fieldsshowon.html which addresses this issue by creating a unique ID for each subform field and each subform row.
There is a drawback with conditional fields in subforms, though. If you are using the table layout for the subform you cannot make the entire column disappear, just the field for that column.
@olivdee Yes, the current implementation in Joomla does not work for subform fields. You should instead use https://www.dionysopoulos.me/software-tools/plg_content_fieldsshowon.html which addresses this issue by creating a unique ID for each subform field and each subform row.
There is a drawback with conditional fields in subforms, though. If you are using the table layout for the subform you cannot make the entire column disappear, just the field for that column.
just installed it, enabled it and still no changes... deleted all caches, logged in again as well. do I need to re create all fields again?
yes, I did add by plus button. what is the mentioned attribute? should I add
min="1"
inside the "Showon Attribute" of containing fields or the subform field?
In the configuration of the custom field for your subform, it should be the option to define at least min 1 row with your fields.
If the showon does work at this first row, it is a JS issue.
It is not a showon attribute.
It is like maximum lines. It is supposed to show the minimum lines on the first call, so to speak.
The option does not seem to exist :-(
It is not a showon attribute. It is like maximum lines. It is supposed to show the minimum lines on the first call, so to speak. The option does not seem to exist :-(
oh man...
will be waiting for an answer of @nikosdion then
many thanks!
Showon works fine in subform field, I suspect it may not work in Custom fields due to this bug #39536, but you have to test
Thanks, but I don't see how this relates to my problem, as I am not having trouble with showing the values in the frontend, but with subform fields to show up on condition while editing an article in the backend. Or maybe I am missing the point? Could you please be a little more specific?
My suspicion is getting stronger and stronger.
It must be a Javascript issue.
Since the dom is already loaded when you click on the plus button and the new line is not considered by the observer, the showon function is not implemented.
My suspicion is getting stronger and stronger. It must be a Javascript issue.
Since the dom is already loaded when you click on the plus button and the new line is not considered by the observer, the showon function is not implemented.
How to check? I gladly do that if guided
My suspicion is getting stronger and stronger. It must be a Javascript issue.
Since the dom is already loaded when you click on the plus button and the new line is not considered by the observer, the showon function is not implemented.How to check? I gladly do that if guided
if this is relevant or helpful:
Just for the record: I just installed from scratch another clean J!4.3, this time on a different server, used the exact above mentioned steps and it is still not working. Afterwards I installed @nikosdion plg_content_fieldsshowon-main.zip and enabled it, still no luck...
FYI: showon.min.js gets loaded when editing the fields, but not when editing an article with those custom fields assigned to it
one question:
Where is the difference between the "Show On" field inside the fields "General" tab vs. the "Showon Attribute" field inside the fields "Options" tab??? BTW, I tried adding "field1:value1" inside both, none worked...
"Show On" field inside the fields "General"
There is not a Show on
field under General tab for the Subform custom field. Only the one under Options
tab exist
I tried adding "field1:value1" inside both, none worked
field[ID]
is only needed when you have the field inside an subform field. Check here
I see, thank you, then "Show On" inside "General" is part of @nikosdion plugin plg_content_fieldsshowon-main.zip - in fact I just disabled the plugin and that field is gone.
Yes, I have that field inside a subform field as explained, that is why I am using it.
In fact I just build that exact thingy without a subform, changed "field1:value1" to "field-list:value1" etc. and it works as expected (without subform and without the aforementioned plugin. Rebuilding it with a subform, using "field1:value1" again, with or without the plugin it does not work... There must be an issue/bug or something very stupid I am missing out here.
I am giving up on this... Tried every combination, with and without the plugin, with the plugins own "Show on" field under General tab and with the native one under Options tab, also with both filled out, made tests with either "field1" (ID) or "field-list" (name), created a fields group as well, added only the list-field to be shown in "Subform Only" and added the two conditional fields to be shown in "Category: All" (here funny thing is, when the plugin is enabled, they do not show up separately with the list-field, when the plugin is disabled they show up) - nothing works...
Maybe somebody can please either confirm that there is actually a bug/error or provide a step-by-step guide on how he did succeed in using this:
I would be very very thankful for this!
Thanks in advance!
yes, so we can give up now :-(
does that mean:
Shouldn't it be the name which is used in showon? I.e. "field-list:1"
?
as far as I understood, only if not used inside a subform, within a subform it is "field[ID]:1"
as far as I understood, only if not used inside a subform, within a subform it is "field[ID]:1"
@olivdee Yes, sorry, now as having read more in detail I see. According to the docs you are right and it should be "field1:1"
(if ID is 1 as shown in your last screenshot. In one of the previous screenshots it was 7).
yes, sorry, it was another server on another older testinstallation - did a new clean one yesterday
and "Content Repeater" contains only "Field List"... so stupid... it HAS to contain all 3, isn't it?
and "Content Repeater" contains only "Field List"... so stupid... it HAS to contain all 3, isn't it?
Yes.
sorry, it was a long day...
I guess I need to look into overriding the admin template in order to hide the not shown/hidden fields, and make the rest full width or shown vertically instead of horizontally or something like that - any hints?
I don't know if I can ask it here but I have a problem with a required field.
When I set a field required but I use also Show on, I can't save the article when the required field is not visible.
It probably sounds logic as the field is required but I had hoped that if the 'show on' hides the field, it also 'hide' it for the validation.
Oeps, sorry that I posted this on the wrong place.
I opened a new issue (I hope the right way, this time ;-)
Hello
@obuisard
Could this lead to the 4.3 series using Showon on the front-end :-) ?
I'm putting it here, as I haven't seen any specific discussion or request on this subject, but I'm not very familiar with github. What's for sure is that several of us have mentioned the importance of not restricting it to the backoffice.
Hello @obuisard Could this lead to the 4.3 series using Showon on the front-end :-) ? I'm putting it here, as I haven't seen any specific discussion or request on this subject, but I'm not very familiar with github. What's for sure is that several of us have mentioned the importance of not restricting it to the backoffice.
Hello @HDInfautre, I apologize for the late answer.
The best would be to open an issue in the issue tracker at https://issues.joomla.org (login with your GitHub account), like that people can comment on it and developers will be aware of the necessity to improve support for showon in the public side of a site.
Hello
Hello @obuisard Could this lead to the 4.3 series using Showon on the front-end :-) ? I'm putting it here, as I haven't seen any specific discussion or request on this subject, but I'm not very familiar with github. What's for sure is that several of us have mentioned the importance of not restricting it to the backoffice.
Hello @HDInfautre, I apologize for the late answer. The best would be to open an issue in the issue tracker at https://issues.joomla.org (login with your GitHub account), like that people can comment on it and developers will be aware of the necessity to improve support for showon in the public side of a site.
Ok, for those interested on this thread, you can vote!? ;-)
https://issues.joomla.org/tracker/joomla-cms/40762
A developer would understand that option, but a user not. I'm not sure if we should expose such a technical attribute to the UI.