In the Hotspots Core extension (download link ) I'm setting some JForm radio fields to disabled. The hotspots config is rendered correctly - the fields display as disabled, but when saving Joomla throws an error:
Invalid field: FIELD_IN_QUESTION
To reproduce you can either install Hotspots Core -> navigate to dashboard -> options and then try to save the options.
Since I know that some people will jump and say - this is extension specific here is an easier way to prove that this is a Joomla issue and has nothing to do with my extension.
Just edit the com_config configuration file:
https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_config/forms/application.xml#L982
and add a disabled="true"
flag on the offline field. Now navigate to the global config(the site offline field should be disabled) and try to save it. You will see:
I would expect to be able to save the form as this was running fine on joomla 3.x and it is normal to have a jform with some disabled fields.
Failure to save
Joomla 4.2
The problem appears to be coming from the validate function in the Form model over here:
https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Form/Form.php#L1215
It seems that on joomla3 the post body that is being sent doesn't contain the disabled fields (which is the correct browser behavior). My suspicion is that something in core.js has changed and that also sends disabled fields in the post body.
Labels |
Added:
No Code Attached Yet
|
@Fedik @joomdonation Any idea?
Look like a bug from our Radio form field. Even the field has disabled attribute set, the value from radio field is still being submitted to server, and it causes that validation error.
Looking more at the code, I can see two possible options to fix this:
If this attribute is not specified, the control inherits its setting from the containing element, for example fieldset; if there is no containing element with the disabled attribute set, and the control itself does not have the attribute, then the control is enabled
From what I see, the disabled attribute is set for the div tag already https://github.com/joomla/joomla-cms/blob/4.0-dev/layouts/joomla/form/field/radio/buttons.php#L87, for some reasons, it is not inherited by the radio options. If I tried to add disabled to the fieldset element https://github.com/joomla/joomla-cms/blob/4.0-dev/layouts/joomla/form/field/radio/buttons.php#L83 , it works. I don't know why.
Maybe @dgrammatiko and @Fedik know it better.
@compojoom A workaround for you while waiting for proper fix is set disabled="true" for each options in the disabled radio field. You did that for some fields already, example:
<field name="footer" label="COM_HOTSPOTS_FOOTER"
description="COM_HOTSPOTS_FOOTER_DESC"
class="btn-group disabled" type="radio" default="1" disabled="true" labelclass="disabled">
<option value="0" disabled="true">JNO</option>
<option value="1" disabled="true">JYES</option>
</field>
@joomdonation I was also first at the impression that the disabled field was sent, but then I could no longer see it in the post request.
If you check the actual data that comes from the post over here:
https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_config/src/Controller/ApplicationController.php#L91
before $oldData you'll see that the disabled field is actually not there.
@compojoom I tested it directly with your component. You can try to add a command to check the submitted data after this line of code https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_config/src/Controller/ComponentController.php#L64
var_dump($data);die();
Then try to change settings from your own component, you will see data for disabled fields (show_contact_author for example) still being submitted to server and that's the reason causing the error
Hm, interesting. Because I'm currently testing by setting the offline field(on the global config) to disabled and it is not being submitted.
@compojoom The offline field using switcher layout, different with your field. You can a sample field to administrator/components/com_config/forms/application.xml , then try to Save configuration, that disabled field will still be submitted:
<field name="test_disabled_radio" label="Test Disabled Radio"
class="btn-group disabled" type="radio" default="0" disabled="true" labelclass="disabled">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
@joomdonation is right, disabled
attribute should be set within fieldset
,
disabled
within div
is invalid.
All attributes for radio buttons should be withing fieldset. In j3 it is correct, in j4 it is incorrect
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-10-30 10:18:52 |
Closed_By | ⇒ | joomdonation |
Ok, I take it back. It is not the javascript.
The submit form just ads a hidden submit button and clicks on it. So basically the browser sends the form per post - no magic here.
I don't know where I was looking, but the submitted post request doesn't contain the disabled field.
The problem comes from this line:
https://github.com/joomla/joomla-cms/blob/4.0-dev/administrator/components/com_config/src/Controller/ApplicationController.php#L91
Basically we are trying to replace the old data with the new data, but that means that any missing disabled fields will be left in the form (if they were previously present).
Any suggestions on a fix?