Bug #42474

Possible bug with short form conditions in viewhelper tags

Added by Thomas Hempel almost 9 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Should have
Category:
ViewHelpers
Target version:
-
Start date:
2012-10-29
Due date:
% Done:

0%

Estimated time:
Has patch:
No

Description

Hi,

I'm not entirely sure, if this is a bug or if do something wrong. Some more people looked at it and considered it as a bug. There fore I'm filing this here right now.

The following statement can be found in my template:

<f:form.textfield name="{foo}" property="{bar}" {f:if(condition:'{disabled}', then:'disabled="disabled"')} />

I would expect a textfield with attribute name and a value. It might also have the attribute set. But what I actually get is this:

<f:form.textfield name="firstname" property="firstname" disabled="disabled" />

(With or without the disabled="disabled")

Am I doing it wrong or is this a bug which should be investigated more?


Related issues

Is duplicate of TYPO3.Fluid - Bug #9454: If condition in viewhelper attributeRejectedAdrian Föder2010-08-25

Actions
#1

Updated by Thomas Hempel almost 9 years ago

Just a small addition. The curly brackets are all solved correctly. But the outer textfield viewhelper is not. It is correct if I remove the condition entirely.

#2

Updated by Bastian Waidelich almost 9 years ago

Hi Thomas,

<f:form.textfield name="{foo}" property="{bar}" {f:if(condition:'{disabled}', then:'disabled="disabled"')} />

Is no valid Fluid syntax unfortunately.

<f:form.textfield name="{foo}" property="{bar}" disabled="{disabled}" />

should work, though

#3

Updated by Thomas Hempel almost 9 years ago

Hi Bastian,

the problem with your solution is, that browser interpret the disabled attribute no matter what it's value is. So with your code it's always disabled which is not what I want. ;-)

The following code will give you 5 disabled fields and one (the last) enabled:

<form>
<input type="text" disabled="0" value="0" />
<input type="text" disabled="1" value="1" />
<input type="text" disabled value="no value" />
<input type="text" disabled="TRUE" value="TRUE" />
<input type="text" disabled="FALSE" value="FALSE" />
<input type="text" value="not set" />
</form>

Beside that, what is wrong with the syntax? Is it really wrong syntax or ist just nested too deep?

#4

Updated by Bastian Waidelich almost 9 years ago

  • Status changed from New to Needs Feedback
  • Assignee set to Bastian Waidelich

Thomas Hempel wrote:

Hi Thomas,

the problem with your solution is, that browser interpret the disabled
attribute no matter what it's value is.

Of course, you're right.
Then you'll probably have to go for

<f:if condition="{disabled}">
  <f:then>
    <f:form.textfield name="{foo}" property="{bar}" disabled="disabled" />
  </f:then>
  <f:else>
    <f:form.textfield name="{foo}" property="{bar}" />
  </f:else>
</f:if>

Beside that, what is wrong with the syntax? Is it really wrong
syntax or ist just nested too deep?

It's wrong, the Fluid parser doesn't detect your tag as fluid viewhelper anymore and skips it.

I'd close the issue if you agree

#5

Updated by Bastian Waidelich almost 9 years ago

  • Status changed from Needs Feedback to Closed

Closing ticket because the syntax is invalid and most probably will never be.
Feel free to re-open if you don't agree or have further comments

#6

Updated by Alexander Dick about 5 years ago

In my opinion, the disabled Attribute should not be added when set "falsy" - it is kind of a special attribute (same as the checked attribute), as soon as the attribute is set, the browser interprets the field as disabled, regardless of the attribute value.

I extended the TagBuilder in my extension, to have that working correctly:

typo3conf/ext/foo/Classes/Core/Fluid/ViewHelper/TagBuilder.php:

<?php
namespace Vendor\Foo\Core\Fluid\ViewHelper;

/**
 *
 * @package Vendor\Foo\Core\Fluid\ViewHelper
 */
class TagBuilder extends \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder {

    /**
     * Renders and returns the tag
     *
     * @return string
     * @api
     */
    public function render() {
        if(empty($this->tagName)) {
            return '';
        }
        $output = '<' . $this->tagName;
        foreach ($this->attributes as $attributeName => $attributeValue) {

            // disabled Attribut nicht einfügen wenn auf 0 gesetzt
            if($attributeName == 'disabled' && !$attributeValue)
                continue;

            $output .= ' ' . $attributeName . '="' . $attributeValue . '"';
        }
        if($this->hasContent() || $this->forceClosingTag) {
            $output .= '>' . $this->content . '</' . $this->tagName . '>';
        } else {
            $output .= ' />';
        }
        return $output;
    }
}

typo3conf/ext/foo/ext_localconf.php

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder'] = array(
    'className' => 'Vendor\\Foo\\Core\Fluid\\ViewHelper\\TagBuilder'
);

Also available in: Atom PDF