Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Form] TimeZoneType generating invalid HTML #8942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fazy opened this issue Sep 5, 2013 · 2 comments
Closed

[Form] TimeZoneType generating invalid HTML #8942

fazy opened this issue Sep 5, 2013 · 2 comments

Comments

@fazy
Copy link

fazy commented Sep 5, 2013

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).

@webmozart
Copy link
Contributor

Thank you for reporting this issue! This is fixed in the linked PR.

fabpot added a commit that referenced this issue Sep 13, 2013
This PR was merged into the 2.3 branch.

Discussion
----------

[Form] Fixed: "required" attribute is not added to <select> tag if no empty value

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8942
| License       | MIT
| Doc PR        | -

Commits
-------

a273e79 [Form] Fixed: "required" attribute is not added to <select> tag if no empty value
@fabpot fabpot closed this as completed Sep 13, 2013
@fazy
Copy link
Author

fazy commented Sep 13, 2013

@bschussek well thanks x 10 for fixing it; I wasn't sure where to look! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants