Skip to content

[Form] TimeZoneType generating invalid HTML #8942

@fazy

Description

@fazy

Not sure if this only affects TimeZoneType, or other use cases of ChoiceType, but the following code:

$builder->add('timezone', 'timezone');

is creating HTML like the following (cut and reformatted):

<select id="form_timezone" name="form[timezone]" required="required">
    <optgroup label="Africa">
        <option value="Africa/Abidjan">Abidjan</option>
        <!-- ... -->
    </optgroup>
    <!-- ... -->
</select>

The problem seems to be the use of required. validator.w3.org gives me this error:

A select element with a required attribute and without a multiple attribute, and whose size is 1, must have a child option element.

This article explains it; from my understanding, I think the problem is that if there is no possible way to select "nothing" (e.g. no option with a blank value), then it's not valid to specify required. In effect, the field is already required because the UI forces a selection.

I think TimeZoneType should generate HTML without "required", but still check for a value server-side (unless the form type is created with 'required' => false of course).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions