Bug #77986
closedChecked option not working in f:form.checkbox
100%
Description
Since TYPO3 8.3, it seems that the checked option in form checkboxes is not working.
The following code produces a checkbox which is not checked
<f:form action="test" name="myForm" >
<f:form.checkbox name="myCheckbox" value="1" checked="checked" />
</f:form>
Same occurs with
<f:form action="test" name="myForm" >
<f:form.checkbox name="myCheckbox" value="1" checked="1 == 1" />
</f:form>
It seems that the $checked variable coming from the registered argument is not evaluated as it was the case when the variable was provided as a parameter of the render() function.
Updated by Claus Due about 8 years ago
If we follow the execution logic from https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/fluid/Classes/ViewHelpers/Form/CheckboxViewHelper.php#L91 to the end of the function it does look like some of the conditions might cause some weird results:
- $propertyValue is possibly not-null in quite a lot of cases
- $checked is overridden if $propertyValue is not-null in the final "elseif" without checking $checked !== null
It should be possible to fix this by changing the condition in https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/fluid/Classes/ViewHelpers/Form/CheckboxViewHelper.php#L110 to also check `$checked !== null` instead of just checking `$propertyValue !== null`.
Updated by Claus Due about 8 years ago
Another possibility is that `$checked` defaults to `false` when the argument is not specified... I don't remember the Fluid logic exactly but we did optimise the way BooleanNode gets created and processed and somewhere during that it is possible we implemented casting of the default value (null) which then becomes `false` which causes the conditions in CheckboxViewHelper to fail (see links above). This should be fairly easy to confirm by debugging the `$checked` variable as soon as it is set (but not in a unit test which creates mock arguments, of course, which is why I haven't tested this - I've no setup, only unit tests currently).
Updated by Laurent Foulloy about 8 years ago
The code generated by the Fluid compiler does not process correctly boolean attributes. Below are parts of the code generated by TYPO3 7.6.9, TYPO3 8.2.1 and TYPO3 8.3.1. In TYPO3 8.3.1, the checked attribute is a string instead of a boolean.
// TYPO3 7.6.9 // Rendering ViewHelper TYPO3\CMS\Fluid\ViewHelpers\Form\CheckboxViewHelper $arguments4 = array(); $arguments4['name'] = 'myCheckbox'; $arguments4['value'] = '1'; // Rendering Boolean node $arguments4['checked'] = TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean('checked'); // TYPO3 8.2.1 // Rendering ViewHelper TYPO3\CMS\Fluid\ViewHelpers\Form\CheckboxViewHelper $arguments6 = array(); $arguments6['name'] = 'myCheckbox'; $arguments6['value'] = 1; // Rendering Boolean node // Rendering Array $array7 = array(); $array7['0'] = 'checked'; $expression8 = function($context) {return "checked";}; $arguments6['checked'] = TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\BooleanNode::convertToBoolean( $expression8( TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\BooleanNode::gatherContext($renderingContext, $array7) ), $renderingContext ); // TYPO3 8.3.1 // Rendering ViewHelper TYPO3\CMS\Fluid\ViewHelpers\Form\CheckboxViewHelper $arguments6 = array(); $arguments6['name'] = 'myCheckbox'; $arguments6['value'] = 1; $arguments6['checked'] = 'checked';
Updated by Laurent Foulloy about 8 years ago
- Priority changed from Should have to Must have
According to the method rewriteBooleanNodesInArgumentsObjectTree() in TYPO3Fluid\Fluid\Core\Parser\SyntaxTree, arguments must be registered as "boolean" to generate boolean nodes.
In TYPO3 8.3, the "checked" and "multiple" arguments in the checkbox viewhelper are registered by means of the registerArgument() but the type is "bool" instead of "boolean". Changing the type to boolean solves the problem.
The same problem occurs in several other viewhelpers.
Updated by Gerrit Code Review almost 8 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51375
Updated by Gerrit Code Review almost 8 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/51375
Updated by Anonymous almost 8 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset e004145901737e9cb465c178be419bd6e9f0bfd2.