Project

General

Profile

Actions

Feature #90181

open

TagBuilder does not support boolean attributes without values

Added by Christian Eßl almost 5 years ago. Updated over 4 years ago.

Status:
Accepted
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2020-01-23
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

TagBuilder::addAttribute() currently cannot add boolean attributes without a value, like:

<input disabled>

To add such an attribute with the TagBuilder, you would currently be required to write something like:

$this->tag->addAttribute('disabled', 'disabled');

which results in:

<input disabled="disabled">

Which is valid, but unnecessary.


Related issues 3 (0 open3 closed)

Related to TYPO3 Core - Feature #90386: Deprecate all form-related ViewHelpers except for f:form in favor of a single "form field name" ViewHelperRejected2020-02-15

Actions
Related to TYPO3 Core - Task #90871: Change AssetCollector ViewHelpers attributes async, defer, nomodule, disabled to booleanClosed2020-03-28

Actions
Related to TYPO3 Core - Bug #94927: <f:form novalidate="false" /> does not work as expectedRejected2021-08-18

Actions
Actions #1

Updated by Claus Due over 4 years ago

Have you checked/confirmed if using `ignoreEmptyAttributes` on TagBuilder makes the boolean attribute "remove itself" as it should?

Actions #2

Updated by Claus Due over 4 years ago

You may like https://forge.typo3.org/issues/90386 and https://review.typo3.org/c/Packages/TYPO3.CMS/+/63264 as substitutes for needing to change API or PHP code for this purpose.

Actions #3

Updated by Christian Eßl over 4 years ago

Thanks, did not notice this feature. This solves the problem.

Actions #4

Updated by Georg Ringer over 4 years ago

  • Related to Feature #90386: Deprecate all form-related ViewHelpers except for f:form in favor of a single "form field name" ViewHelper added
Actions #5

Updated by Georg Ringer over 4 years ago

As the mentioned patch is still heavily WIP I would propose to hardcode those values which are boolean

    "allowfullscreen",
    "allowpaymentrequest",
    "async",
    "autofocus",
    "autoplay",
    "checked",
    "controls",
    "default",
    "defer",
    "disabled",
    "formnovalidate",
    "hidden",
    "ismap",
    "itemscope",
    "loop",
    "multiple",
    "muted",
    "nomodule",
    "novalidate",
    "open",
    "readonly",
    "required",
    "reversed",
    "selected",
    "typemustmatch" 
Actions #6

Updated by Claus Due over 4 years ago

  • Status changed from New to Accepted

A hardcoded list of attributes is not advisable and would require a change in Fluid, but would be rejected there - arguing that not all XML-like output formats require or are even compatible with XHTML boolean attributes.

Suggested approach in TYPO3 CMS:

  • Do not declare more ViewHelper arguments on tag-based ViewHelpers as strictly "boolean" and do not implement the special logic that would be required to assign the attribute with a string value if TRUE. This makes the API of said ViewHelpers different from standard XHTML which introduces possible confusion (why do I need to pass TRUE in Fluid when I need to pass a string value in XHTML?)
  • Instead, adjust ViewHelpers which require this type of logic, to use "ignoreEmptyAttributes" on TagBuilder to prevent rendering attributes when their value is an empty string.
  • Possibly also remove the argument definition and implement "handleAdditionalArguments" to pass undeclared arguments (or only a specific list of such arguments) directly as tag attributes (this might be considered a FEATURE and as such it might be skipped for v10 LTS)

Alternative for Fluid library:

  • Feel free to open a pull request that changes default value of "ignoreEmptyAttributes" on TagBuilder to TRUE.
  • But be aware that this would considered breaking, meaning it would only be implemented in Fluid 3.x branches.
Actions #7

Updated by Georg Ringer over 4 years ago

  • Related to Task #90871: Change AssetCollector ViewHelpers attributes async, defer, nomodule, disabled to boolean added
Actions #8

Updated by Česlav Przywara about 3 years ago

  • Related to Bug #94927: <f:form novalidate="false" /> does not work as expected added
Actions

Also available in: Atom PDF