? Language Change Documentation Required PR-4.3-dev Pending

User tests: Successful: Unsuccessful:

avatar obuisard
obuisard
23 Oct 2022

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.

Summary of Changes

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.

Testing Instructions

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.

Actual result BEFORE applying this Pull Request

All fields show on a form (by default, unless some other parameter have been set).

Expected result AFTER applying this Pull Request

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!

Link to documentations

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

avatar obuisard obuisard - open - 23 Oct 2022
avatar obuisard obuisard - change - 23 Oct 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 23 Oct 2022
Category Administration com_fields Language & Strings
avatar laoneo
laoneo - comment - 23 Oct 2022

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.

avatar obuisard
obuisard - comment - 23 Oct 2022

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?

avatar degobbis
degobbis - comment - 23 Oct 2022

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

avatar obuisard
obuisard - comment - 23 Oct 2022

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

avatar HLeithner
HLeithner - comment - 23 Oct 2022

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.

avatar obuisard obuisard - change - 23 Oct 2022
Labels Added: Language Change Documentation Required PR-4.3-dev
avatar brianteeman
brianteeman - comment - 23 Dec 2022

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

avatar brianteeman brianteeman - test_item - 23 Dec 2022 - Tested successfully
avatar brianteeman
brianteeman - comment - 23 Dec 2022

I have tested this item successfully on c154e73


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39051.

avatar alikon alikon - test_item - 23 Dec 2022 - Tested successfully
avatar alikon
alikon - comment - 23 Dec 2022

I have tested this item successfully on c154e73


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39051.

avatar crystalenka
crystalenka - comment - 23 Dec 2022

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.

avatar richard67 richard67 - change - 23 Dec 2022
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 23 Dec 2022

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39051.

avatar obuisard
obuisard - comment - 23 Dec 2022

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.

avatar obuisard
obuisard - comment - 23 Dec 2022

Thank you Brian @brianteeman and Nicola @alikon for testing this PR!

avatar degobbis
degobbis - comment - 23 Dec 2022

Is there now a solution for the output in the frontend?

avatar carlitorweb
carlitorweb - comment - 10 Jan 2023
avatar obuisard
obuisard - comment - 10 Jan 2023

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.

avatar carlitorweb
carlitorweb - comment - 10 Jan 2023

@obuisard thank you for the correction, I added it.

avatar obuisard
obuisard - comment - 10 Jan 2023

@obuisard thank you for the correction, I added it.

Thank you so much!

avatar obuisard
obuisard - comment - 10 Jan 2023

Is there now a solution for the output in the frontend?

Nobody came forward with a solution at this time.

avatar HLeithner HLeithner - change - 12 Jan 2023
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: ?
avatar HLeithner HLeithner - close - 12 Jan 2023
avatar HLeithner HLeithner - merge - 12 Jan 2023
avatar HDInfautre
HDInfautre - comment - 24 Feb 2023

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

avatar olivdee
olivdee - comment - 24 Apr 2023

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:

image

  • "Field List" with ID 7 has 3 List Values as seen here:
    image

  • "Conditional Text" has the following Showon Attribute: field7:value1
    image

  • "Conditional Image" has the following Showon Attribute: field7:value2
    image

  • Upon editing an article, the "Conditional Fields" do not appear after selecting the corresponding List Values - it works though if not inside a Subform!
    image

Any idea?

avatar degobbis
degobbis - comment - 24 Apr 2023

@olivdee are the fields inserted by default (attribute min="1" of subform) or have You add it by plus button?

avatar nikosdion
nikosdion - comment - 24 Apr 2023

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

avatar olivdee
olivdee - comment - 24 Apr 2023

@olivdee are the fields inserted by default (attribute min="1" of subform) or have You add it by plus button?

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?

avatar olivdee
olivdee - comment - 24 Apr 2023

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

avatar degobbis
degobbis - comment - 24 Apr 2023

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.

avatar olivdee
olivdee - comment - 24 Apr 2023

dankeschön, but I tried adding min="1" on both places where "Showon" is mentioned (one for each test, not inside both at once):
image
and
image

it does not work and for both places I get this in the console:
image

avatar degobbis
degobbis - comment - 24 Apr 2023

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 :-(

avatar olivdee
olivdee - comment - 24 Apr 2023

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!

avatar Fedik
Fedik - comment - 24 Apr 2023

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

avatar olivdee
olivdee - comment - 25 Apr 2023

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?

avatar degobbis
degobbis - comment - 25 Apr 2023

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.

avatar olivdee
olivdee - comment - 25 Apr 2023

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

avatar olivdee
olivdee - comment - 25 Apr 2023

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:

  • in devtools network tab there is no blocked request or 404 status, but there is also no showon.js or showon.min.js loaded (if those are the related/needed files in order for this to work), nor is there a console error of any kind
  • also if I remove the min="1" showon attribute, then there is no more error in console
avatar olivdee
olivdee - comment - 25 Apr 2023

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

avatar olivdee
olivdee - comment - 26 Apr 2023

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

avatar carlitorweb
carlitorweb - comment - 26 Apr 2023

"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

avatar olivdee
olivdee - comment - 26 Apr 2023

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.

avatar olivdee
olivdee - comment - 26 Apr 2023

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:

  1. Field List with 2 different list values
  2. Conditional Field 1 shown only on Field List with value1 and the respective "Showon Attribute" inside "Options" tab
  3. Conditional Field 2 shown only on Field List with value2 and the respective "Showon Attribute" inside "Options" tab
  4. Subform Field (Content Repeater) with the repeatable Field List inside
  5. Test Article with the Subform Field, when either of the 2 Field List values are selected, the respective Conditional Field should appear:
    image

I would be very very thankful for this!
Thanks in advance!

avatar degobbis
degobbis - comment - 26 Apr 2023

@olivdee just to make sure we are using this correctly:
the 1 in field1 is not the field number 1 in the sequence, but there should be the fieldID.

So the same number as if you were adding the field in the article to the content.

avatar olivdee
olivdee - comment - 26 Apr 2023

yes:
image
image
image

this is what you mean and what I understood, is that correct?

avatar degobbis
degobbis - comment - 26 Apr 2023

yes, so we can give up now :-(

avatar olivdee
olivdee - comment - 26 Apr 2023

does that mean:

  1. nobody fully tested this till the end?
  2. somebody did once upon a time, it was working, but it is broken now?
  3. it is not broken, it actually works, but there is some spectacular miss on my side, or I am too stupid to get it done?
avatar richard67
richard67 - comment - 26 Apr 2023

Shouldn't it be the name which is used in showon? I.e. "field-list:1"?

avatar olivdee
olivdee - comment - 26 Apr 2023

as far as I understood, only if not used inside a subform, within a subform it is "field[ID]:1"

avatar richard67
richard67 - comment - 26 Apr 2023

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

avatar olivdee
olivdee - comment - 26 Apr 2023

yes, sorry, it was another server on another older testinstallation - did a new clean one yesterday

avatar carlitorweb
carlitorweb - comment - 26 Apr 2023

@olivdee I in fact right now working in a site and using a conditional custom field inside a subform, and is workig as expected

Captura

avatar carlitorweb
carlitorweb - comment - 26 Apr 2023

@olivdee can you set the "Conditional Text" as Only Use In Subform and check again. You need have both fields with Only Use In Subform as Yes

avatar olivdee
olivdee - comment - 26 Apr 2023

thank you for confirming that it is working! I was using both fields only use in subform, actually like this:
image

avatar olivdee
olivdee - comment - 26 Apr 2023

and "Content Repeater" contains only "Field List"... so stupid... it HAS to contain all 3, isn't it?

avatar richard67
richard67 - comment - 26 Apr 2023

and "Content Repeater" contains only "Field List"... so stupid... it HAS to contain all 3, isn't it?

Yes.

avatar olivdee
olivdee - comment - 26 Apr 2023

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?

avatar FilMar61
FilMar61 - comment - 5 May 2023

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.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39051.

avatar obuisard
obuisard - comment - 5 May 2023

@FilMar61 do you mind opening an issue in the issue tracker? That way we can have people look at it, confirm this is the case, and have it processed. Thank you!

avatar FilMar61
FilMar61 - comment - 5 May 2023

Oeps, sorry that I posted this on the wrong place.
I opened a new issue (I hope the right way, this time ;-)

avatar obuisard
obuisard - comment - 5 May 2023

Oops, sorry that I posted this on the wrong place. I opened a new issue (I hope the right way, this time ;-)

No problem @FilMar61! It will have more visibility than the merged PR :-)

avatar HDInfautre
HDInfautre - comment - 2 Jun 2023

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.

avatar obuisard
obuisard - comment - 12 Jun 2023

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.

avatar HDInfautre
HDInfautre - comment - 13 Jun 2023

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

Add a Comment

Login with GitHub to post a comment