Project

General

Profile

Actions

Bug #86164

closed

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

Added by Julian Stelzer about 6 years ago. Updated over 5 years ago.

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

100%

Estimated time:
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 1 (0 open1 closed)

Related to TYPO3 Core - Bug #86890: AbstractTagBasedViewHelper recycles the TagBuilderClosed2018-11-08

Actions
Actions #1

Updated by Susanne Moog about 6 years ago

  • Target version changed from 9 LTS to next-patchlevel
Actions #2

Updated by Sascha Wilking almost 6 years 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="">
Actions #3

Updated by Rémy DANIEL almost 6 years 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?

Actions #4

Updated by Rémy DANIEL almost 6 years 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 :-)

Actions #5

Updated by Mathias Brodala over 5 years 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.

Actions #6

Updated by Rémy DANIEL over 5 years ago

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

Actions #7

Updated by Rémy DANIEL over 5 years ago

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

Updated by Jonas Eberle over 5 years ago

  • % Done changed from 0 to 100
Actions #9

Updated by Julian Stelzer over 5 years ago

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

Actions #10

Updated by Benni Mack over 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF