User tests: Successful: Unsuccessful:
Pull Request for Issue #12810.
Adds a callback functionality for form fields to prepare the value of a custom field before the value is passed to the form.
When editing the article the 0 checkbox should be selected. On the frontend "No" should be displayed.
No checkbox is selected in the form and nothing is displayed when viewing an article.
Status | New | ⇒ | Pending |
Category | ⇒ | Administration com_fields Front End Libraries |
??
This code basically is only needed for the checkboxes field, right? And only to be used by com_fields?
Looks a bit strange to me then.
Since the checkboxes field works fine with JForm, I'd expect a fix in com_fields, not in the JFormField.
It allows a field to influence the value. If some more advanced fields will be created in the future they can then influence how a value is set on the form.
But right now it is only used in custom fields. What I want to prevent is to use field specific code in com_fields itself.
they can then influence how a value is set on the form
Isn't that already done with getInput?
The issue is only in com_fields in how it tries to guess if it should show the field value or not (I think). But as written in the issue I haven't found where the difference comes from. My guess was it's related to "forceMultiple" being true in the checkboxes field.
What I want to prevent is to use field specific code in com_fields itself.
Good idea
The problem lies here https://github.com/joomla/joomla-cms/blob/staging/administrator/components/com_fields/models/field.php#L581 where no array is set when it is a single row value.
And what does JForm differently that we get an array even with only one value? That's what I haven't found out yet. Something must be different and I think it's the cause for this issue.
I'v tested it adding a checkboxs field to the attribs fieldset. There it is stored as array when it get's json encoded.
I see, if a field has the attribute "multiple" set (also list fields), then the value is stored as array in the JSON string.
Most fields however can process strings as well since the attribute is optional. In the case of the checkboxes it (rightfully) always expects an array since it has forceMultiple property set to true.
I don't think we can check the multiple property correct since it's set during runtime of the field based on the forceMultiple property. Or do you see a way for that? Then it would be simple.
If we have to adjust the checkboxes field anyway I'd rather just cast the value to array and be done.
I don't really understand what this forceMultiple property does. Just had a quick look on it.
It ensures $this->multiple
is always true and thus the value is always saved as an array
forceMultiple did the trick
Looks much better this way. Thanks!
Title |
|
Title |
|
I have tested this item
Yes, that's different
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
Milestone |
Added: |
Done
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-12-07 08:30:14 |
Closed_By | ⇒ | rdeutz |
Thanks.
So we need a prepareValue method to for this FormField?