Project

General

Profile

Actions

Bug #101182

open

Checkbox is always checked for each value in a form with object property with a value

Added by Florian Rival 10 months ago. Updated 10 months ago.

Status:
Under Review
Priority:
Should have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2023-06-27
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.4
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

Add a Fluid Template with a form and a checkbox bind to object property like this :

<f:form action="..." name="country" object="{country}">
  <f:form.checkbox property="money" value="dollar" />
  <f:form.checkbox property="money" value="euro" />
  <f:form.checkbox property="money" value="yen" />
</f:form>

If object property already has a value, ex. : country.money = euro
Then all check boxes have the attribute checked while only the second one should be checked.

The problem is because the CheckboxViewHelper cast the values in boolean while it could be everything (string, int, boolean, etc.).

$checked = (boolean)$propertyValue === (boolean)$valueAttribute;

Actions #1

Updated by Gerrit Code Review 10 months ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/79523

Actions #2

Updated by Gerrit Code Review 10 months ago

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/79528

Actions #3

Updated by Gerrit Code Review 10 months ago

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/79693

Actions #4

Updated by Gerrit Code Review 10 months ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/79528

Actions #5

Updated by Gerrit Code Review 10 months ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/79523

Actions #6

Updated by Simon Praetorius 10 months ago

I think that the current behavior of the CheckboxViewHelper is correct here. The case you described 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().

Actions #7

Updated by Florian Rival 10 months ago

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

Actions

Also available in: Atom PDF