Bug #86164

CheckboxViewHelper sets automatically each checkbox on checked, if just one of them is checked

Added by Julian Stelzer 9 months ago. Updated about 1 month ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
Start date:
2018-09-06
Due date:
% Done:

100%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

If you want to use more than one checkbox in your form, for example a choice of categories in a simple FE-search and you set them like this.

<f:for each="{suche.options}" as="option" key="value">

     <f:form.checkbox property="category" multiple="true" value="{value}" id="check_{value}" />

  </f:for>

After you sent the form via POST just your selected checbox should be marked (checked="checked"), but instead all checkboxes after your last marked checkbox are marked too.

E.g.
______________________________
Your Search word: Example

cat 1 []
cat 2 [x]
cat 3 []
cat 4 []

-> you send this, but after reload with the values

Your Search word: Example

cat 1 []
cat 2 [x]
cat 3 [x]
cat 4 [x]

-> cat 2-4 are marked too.
________________________________

The problem seems to be the CheckBoxViewHelper. The following code doesn't remove the checked tag from the next checkboxes.

if ($checked === true) {
            $this->tag->addAttribute('checked', 'checked');
        }

So if I add the else-case, it works as it should.

        if ($checked === true) {
            $this->tag->addAttribute('checked', 'checked');
        }
        else {
            $this->tag->removeAttribute( 'checked');
        }

The bug was first located in TYPO3 9.3 ( I don't know, if it was there earlier)


Related issues

Related to TYPO3 Core - Bug #86890: AbstractTagBasedViewHelper recycles the TagBuilder Closed 2018-11-08

History

#1 Updated by Susanne Moog 9 months ago

  • Target version changed from 9 LTS to next-patchlevel

#2 Updated by Sascha Wilking 6 months ago

It's the same problem by other attributes as well. I.e.

<f:for each="{themeOptions}" as="tag">
   <f:form.checkbox multiple="true" class="{f:if(condition:tag.disabled,then:'disabled',else:'')}" property="tagTheme" value="{tag.uid}" />
</f:for>

As soon as the "disabled" class is added to a checkbox, all subsequent checkboxes also get this class, which is wrong.

<input type="checkbox" name="articleFilter[tagTheme][]" value="1" checked="checked" class="">
<input type="checkbox" name="articleFilter[tagTheme][]" value="2" checked="checked" class="disabled">
<input type="checkbox" name="articleFilter[tagTheme][]" value="3" checked="checked" class="disabled">
<input type="checkbox" name="articleFilter[tagTheme][]" value="4" checked="checked" class="disabled">

Only the second element should get this class.

The following code works:

<f:if condition="{tag.disabled}">
   <f:then><f:form.checkbox multiple="true" class="disabled" property="tagTheme" value="{tag.uid}" /></f:then>
   <f:else><f:form.checkbox multiple="true" property="tagTheme" value="{tag.uid}" /></f:else>
</f:if>

Here is the result:

<input type="checkbox" name="articleFilter[tagTheme][]" value="1" checked="checked" class="">
<input type="checkbox" name="articleFilter[tagTheme][]" value="2" checked="checked" class="disabled">
<input type="checkbox" name="articleFilter[tagTheme][]" value="3" checked="checked" class="">
<input type="checkbox" name="articleFilter[tagTheme][]" value="4" checked="checked" class="">

#3 Updated by DANIEL Rémy 4 months ago

Hello

For me the problem occurs only just after clearing the core cache.
When the fluid template is compiled, the problem does not happen.

While debugging the viewhelper rendering, in a loop of 4 checkboxes, I found that the __construct of the viewhelper class (AbstractTagBasedViewHelper) is called only once.
The second time the template is rendered, the __construct is properly called 4 times.
The __construct of AbstractTagBasedViewHelper is responsible of building a fresh tagBuilder with default attributes values.

Clearing the core cache introduces again the issue.

So, why when the fluid template is first rendered, the tagBuilder is not unique in a for loop?

#4 Updated by DANIEL Rémy 4 months ago

I suspect something like that.

- when compiling, the fluid template is parsed
- each node are instanciated
- in the template, the f:form.checkbox VH appears only one time in the f:for VH, so it is instanciated only once
- the compiled template is cached
- the template is rendered but with the in memory parsed template and the existing VH instances

When the template is already compiled, the rendering of all f:form.checkbox is now done from ForViewHelper::renderStatic method,
and all f:form.checkbox are now each with a fresh instance of tagBuilder.

This issue must be analized by a Fluid guru :-)

#5 Updated by Mathias Brodala 3 months ago

  • Status changed from New to Resolved

This was fixed with Fluid 2.6.0. You can either update yourself or update to TYPO3 9.5.5 which requires at least this version.

#6 Updated by DANIEL Rémy 3 months ago

I confirm that the issue is not present anymore with TYPO3 9.5.5
Thanks!

#7 Updated by DANIEL Rémy 3 months ago

  • Related to Bug #86890: AbstractTagBasedViewHelper recycles the TagBuilder added

#8 Updated by Jonas Eberle 3 months ago

  • % Done changed from 0 to 100

#9 Updated by Julian Stelzer 3 months ago

My bug is still there, tested with 9.5.6.dev.

#10 Updated by Benni Mack about 1 month ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF