Feature #90181
openTagBuilder does not support boolean attributes without values
0%
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.
Updated by Claus Due almost 5 years ago
Have you checked/confirmed if using `ignoreEmptyAttributes` on TagBuilder makes the boolean attribute "remove itself" as it should?
Updated by Claus Due almost 5 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.
Updated by Christian Eßl almost 5 years ago
Thanks, did not notice this feature. This solves the problem.
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
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"
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.
Updated by Georg Ringer over 4 years ago
- Related to Task #90871: Change AssetCollector ViewHelpers attributes async, defer, nomodule, disabled to boolean added
Updated by Česlav Przywara over 3 years ago
- Related to Bug #94927: <f:form novalidate="false" /> does not work as expected added