-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional custom fields with showon #39051
Conversation
Added the showon attribute entry to the form options
Added label and description keys for the showon attribute parameter
Added the showon attribute to the node creation in onCustomFieldsPrepareDom
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. |
Thank you, Guido. |
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. |
Better wording for key Co-authored-by: Brian Teeman <brian@teeman.net>
Co-authored-by: Quy <quy@nomonkeybiz.com>
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 ✅ successfully on c154e73 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39051. |
1 similar comment
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. |
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. |
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39051. |
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 |
Super Carlos @carlitorweb ! However, we probably should mention the specific case when dealing with |
@obuisard thank you for the correction, I added it. |
Thank you so much! |
Nobody came forward with a solution at this time. |
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: |
There is not a
|
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. |
@olivdee just to make sure we are using this correctly: So the same number as if you were adding the field in the article to the content. |
yes, so we can give up now :-( |
does that mean:
|
Shouldn't it be the name which is used in showon? I.e. |
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 |
yes, sorry, it was another server on another older testinstallation - did a new clean one yesterday
|
@olivdee I in fact right now working in a site and using a conditional custom field inside a subform, and is workig as expected |
@olivdee can you set the "Conditional Text" as |
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 don't know if I can ask it here but I have a problem with a required field. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39051. |
@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! |
Oeps, sorry that I posted this on the wrong place. |
No problem @FilMar61! It will have more visibility than the merged PR :-) |
Hello |
Hello @HDInfautre, I apologize for the late answer. |
Hello
Ok, for those interested on this thread, you can vote!? ;-) |
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