1) Set error reporting in Joomla configuration to maximum.
2) Use a form with a GroupedList field.
3) Select some items and save the form
4) Put the attribute readonly of the field by code or by the manifest of the form.
5) Reopen the form
6) You'll see a PHP warning htmlspecialchars() expects parameter 1 to be string, array given in /libraries/joomla/form/fields/groupedlist.php on line 169
Suggested solution
I suggest to do the same thing than in the List field.
Even if Icouldn't see a warning (error_reporting Maximum), you're right, this form field doesn't support readonly.
@test Success after patch. Tested disabled, readonly, multiple.
Because it was hard for me to find a form with groupedlist field:
My test:
Add to /administrator/.../com_content/...forms/article.xml
below line 147 (< fieldset name="basic" label="COM_CONTENT_ATTRIBS_FIELDSET_LABEL" >)
The desabled attribute is set when the readonly attribute is present to avoid user's confusion, otherwise the grouplist could be changed by the user.
In addition, when the readonly attribute is present, the name of the groupedlist is not set and in the same time another input of type hidden is created with the name of the grouplist to send the value of the field.
I read the reply by @colivier but I am not sure I fully understand. If in the XML definition the field is set to be readonly, the field shouldn't be disabled, it should be made readonly. Sure a field can be changed by the user but that is up to the person who decides to use this field with such a setting.
So I do think we need to change the readonly to be readonly and not disabled.
@colivier Yes, I was able to reproduce the issue. Your change fixes the issue but also touches another issue. That issue is that the readonly and disabled are treated the same way. That is what Roberto commmented on. However, seeing that the same "fix" is applied in the list field, I would say let's accept your proposal.
Even if Icouldn't see a warning (error_reporting Maximum), you're right, this form field doesn't support readonly.
@test Success after patch. Tested disabled, readonly, multiple.
Because it was hard for me to find a form with groupedlist field:
My test:
Add to /administrator/.../com_content/...forms/article.xml
below line 147 (< fieldset name="basic" label="COM_CONTENT_ATTRIBS_FIELDSET_LABEL" >)
these lines:
Now you see this field in article edit view > Tab Options.
And can add readonly and/or multiple and so on....