Skip to content

Commit 32f0b7b

Browse files
minor #44464 [TwigBridge] Provide a default non-empty label on empty options to validate HTML5 (DocFX)
This PR was merged into the 6.2 branch. Discussion ---------- [TwigBridge] Provide a default non-empty label on empty options to validate HTML5 | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | As described on https://rocketvalidator.com/html-validation/element-option-without-attribute-label-must-not-be-empty, so far this template generates empty options with no value, no content, and no label. This is not a break, but a simple "should". Not sure how we should recommend handling this, users have the possibility to handle this themselves (https://symfony.com/doc/current/reference/forms/types/choice.html#placeholder), but if they don't we leave a non-stadanrd-compliant output. The tailwind template is also affected from this, as it extends this one. I proposed a double-dash default value: - pretty affordant - doesn't use translations as users might not use them - doesn't suffer from language dependent doubtful meaning I locally fix this by overriding the default templates, but I thought the default ones could get a fix. Also, to make it quick, I proposed to change this starting 5.4. Maybe we can push this back to 4.4? Commits ------- f9aff39706 [TwigBridge] Provide a default non-empty label on empty options to validate HTML5
2 parents 6ec7e1e + 0ba5065 commit 32f0b7b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
{%- endif -%}
6262
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
6363
{%- if placeholder is not none -%}
64-
<option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (translation_domain is same as(false) ? placeholder : placeholder|trans({}, translation_domain)) }}</option>
64+
<option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (translation_domain is same as(false) ? placeholder : placeholder|trans({}, translation_domain)) : '--' }}</option>
6565
{%- endif -%}
6666
{%- if preferred_choices|length > 0 -%}
6767
{% set options = preferred_choices %}

0 commit comments

Comments
 (0)