79523[BUGFIX] Correct error for selected checkbox bind to object property
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 1
Review log 911
-
Florian Rival uploaded patch set 1 06/27/23, 17:08
-
core-ci voted on patch set 1 V -1 06/27/23, 17:17 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43044
-
Benni Mack updated the commit message in patch set 2
V -107/05/23, 17:13 -
core-ci voted on patch set 2 V -1 07/05/23, 17:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/43563
-
Simon Praetorius commented on patch set 2 CR -1 07/05/23, 17:50
I think that the current behavior of the CheckboxViewHelper is correct here. The case you described in Forge would be better covered by a set of radio buttons instead of checkboxes. The RadioViewHelper doesn't convert the values to booleans. A valid use case for multiple checkboxes would be if you could select multiple options (in your example currencies). This case is covered by the CheckboxViewHelper by checking for is_array(). -
Florian Rival commented on patch set 2 07/11/23, 09:55
Reply
I don't agree with you, in HTML we can assign values to checkboxes and those values are sent to the server. If you have a look at TYPO3's documentation : https://docs.typo3.org/other/typo3/view-helper-reference/main/en-us/typo3/fluid/latest/Form/Checkbox.html?highlight=checkbox, you can see a similar example : <f:form.checkbox property="interests" value="TYPO3" /> This case won't work if the property bind to object already has a value and it should. The patch I wrote, compares the values with the same type - the type of object property - it should then cover all the cases. Checkboxes can contain any kind of value and not only boolean -
Simon Praetorius commented on patch set 2 07/11/23, 10:24
Reply
I agree with you that it is technically possible with HTML to send an arbitrary string to the server using a checkbox. However, I think that this only makes sense in practice if you want to receive an array of values, not a single one. This is also the example that is covered by the documentation (note that interests is plural). The documentation states: Output: <input type="checkbox" name="user[interests][]" value="TYPO3" checked="checked" /> Which indicates that the property "interests" is defined as an array and thus [] is added to the input's name and the values aren't converted to boolean. In your example in Forge however, you define multiple checkboxes but want to receive a string, which is technically possible but doesn't make sense to me. You would only receive the last checkbox that was checked by the user, not the other checked ones. -
Florian Rival commented on patch set 2 07/11/23, 10:46
Reply
Yes but in my case, I don't want a radiobutton because I want to check or uncheck the checkbox which is not possible with a radio button without JavaScript. Then I need a checkbox and I need to send a string value to the server in order to know which checkbox was chedked. -
Simon Praetorius commented on patch set 2 07/13/23, 08:40
Reply Unresolved
I just looked into this again. I created the following test setup: * TYPO3 Core without your patch * Extbase PlugIn with Fluid template * object with property "flag" * Fluid template with form tag using the object and a checkbox using "flag" If I use the following Fluid (which I think is quite common): <f:form.checkbox property="flag" value="1" /> * For flag=true, flag=1 and flag='1' the checkbox will be checked. * For flag=false, flag=0 and flag='0' the checkbox will be unchecked. With your change, the checkbox is only checked if flag=1. In my opinion, the current implementation has the right balance between flexibility and pragmatism. If we change this, it would probably break a lot of projects out there, for a case that in my opinion is quite niche. I would suggest that you create your own checkbox ViewHelper for your case and that we leave the implementation in core as-is. -
Benni Mack updated the commit message in patch set 3
CR -1V -110/18/24, 14:10 -
Benni Mack abandoned the change 03/08/25, 20:26
See last comment from Simon, will abandon this change now after almost 2 years.