Bug #77986
closed
Checked option not working in f:form.checkbox
Added by Laurent Foulloy about 8 years ago.
Updated about 6 years ago.
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.
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).
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';
- 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.
- Status changed from New to Under Review
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
- Status changed from Resolved to Closed
Also available in: Atom
PDF