? No Code Attached Yet
avatar crystalenka
crystalenka
20 Nov 2022

Was an issue, wrongly converted to discussion, bringing it back as an issue so that someone can see it and maybe submit a PR.

Discussed in #39211

Originally posted by frogydiak April 2, 2022

Steps to reproduce the issue

Create an xml field and set the shownon attribute to whatever is the value of another field then set the attribute to "required=true". You'll get an error while saving that it cannot be saved because a required data is missing or something like that.

Expected result

Shouldn't it check for "shownon"? If set and not enabled, bypass the field required validation and if enabled then it validate for required value?

Actual result

The validation of required field does not check the field showon attribute value.

Additional comments

I don't know if this is a bug, but looking at it as in an end user perspective it is a bug. First thing that comes to my minds is "That field is not enabled, why do I have to enter a value?" .

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar crystalenka crystalenka - open - 20 Nov 2022
avatar wilsonge
wilsonge - comment - 4 Dec 2022

Showon was originally always setup to be a purely visual thing. For example where we used memcached in global configuration (where the fields aren't required unless the option is enabled). Whilst I understand what the desired behaviour is from the end user perspective it's really tricky because we start making validation dependent on the user submitted data which is really tricky. We can cause security issues really fast if we get it wrong

Original feature issue for some backstory (admittedly limited):
#1240
https://developer.joomla.org/joomlacode-archive/issue-31100.html

avatar Hackwar Hackwar - change - 22 Feb 2023
Labels Added: No Code Attached Yet bug
avatar Hackwar Hackwar - labeled - 22 Feb 2023
avatar Hackwar Hackwar - change - 22 Feb 2023
Labels Added: ?
Removed: bug
avatar Hackwar Hackwar - unlabeled - 22 Feb 2023
avatar Hackwar Hackwar - labeled - 22 Feb 2023
avatar degobbis
degobbis - comment - 24 Feb 2023

@wilsonge There may be a simple solution to this.

Form fields that have the attribute "disabled" are not submitted by the browser.

You would have to take this into consideration in the javascript and provide hidden fields with this attribute, or remove it again if displayed.

I have already implemented this in one of my extensions, but I am not experienced enough to adapt it in the core.
I already asked @fancyFranci about it and showed her my solution. I would be happy to help her with the implementation.

avatar jjnxpct
jjnxpct - comment - 4 May 2023

I started using the custom fields field 'Showon Attribute' and also was wondering what would happen when a field is not shown (based on the Showon Attribute) but IS required. I tried it and Joomla won't save the article when the hidden field is empty and required.

So if Joomla could disable the 'required' value when the field is hidden that would make sense. Right?

Also taking this a bit further: When a veld is first shown (based on an other field) and a value has been entered by the user, and then was hidden because the user changed the value of the related field, it might be logical to remove the entered value from the hidden field. Maybe not right away when the other field is changed, but on save?

Just thinking out loud ;-)

I also read somewhere someone proposed a 'Required On' attribute. Maybe that is a better way to handle this. So a field will be required based on the value of another field.

avatar FilMar61
FilMar61 - comment - 7 Jul 2023

I have also noticed the same problem and agree with the original poster, and created an issue about it (#40547) but I was redirected to here.
When a field is set to required and it is hidden by the Showon property it should not be validated. I don't find the 'workaround' with a default value practical if you use the field also for filtering (in the case of dropdowns or checkboxes).

I also have the same toughts as @jjnxpct. When a field is shown first and is filled but later is hidden by changing the related field then at some point that field 's value need to be cleared (or needs an option to be cleared or not). I vote also for the clearing at record save. Here again for the same reason, otherwise you create false data that can give false results when filtering the data.
I created also an issue for this (#40548) but I suppose it can be closed if both are continued here.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39257.
avatar degobbis
degobbis - comment - 26 Jul 2024

Let me expand a little:
In Joomla, on the server side, there are some checks to prevent form fields from being manipulated.
For example, submitted fields are checked against the manifest XML, which means that submitted fields with the “required” attribute must not be empty (which is correct). It is therefore useless to simply remove the “required” in the output, it only solves the problem on the browser side.
The keyword is: “submitted fields”.
Fields that have not been submitted are therefore not checked either, logically :-)
I have used this fact in one of my extensions and, with my simple JS knowledge, extended the ShowOn functionality so that hidden fields are given the “disabled” attribute.
Either the fields are not transmitted by the browser at all, or Joomla has a cleaning function that removes these fields from the transmission.
Either way, this ensures that hidden fields are no longer a problem if they are “required” and hidden.
If a JS professional is able to implement this in the core, it would solve the problem.
Here is the script how I do it: https://github.com/joomtools/plg_content_jtf/blob/5.x-dev/src/media/plg_content_jtf/js/es6/jtfShowon.es6

To activate this in subforms as well, I have implemented the following in the layout: https://github.com/joomtools/plg_content_jtf/blob/5.x-dev/src/plugins/content/jtf/layouts/joomla/form/field/subform/repeatable_tmpl.php#L107-L113

Maybe you can find a professional.

Add a Comment

Login with GitHub to post a comment