Skip to content
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

Unexpected select/option error #47

Closed
astorije opened this issue Mar 5, 2015 · 4 comments
Closed

Unexpected select/option error #47

astorije opened this issue Mar 5, 2015 · 4 comments

Comments

@astorije
Copy link

@astorije astorije commented Mar 5, 2015

When validating the public page of W3C's Specberus, I am getting the following error:

Error: The first child option element of a select element with a required attribute and
       without a multiple attribute, and whose size is 1, must have either an empty
       value attribute, or must have no text content.
From line 105, column 29; to line 105, column 58
          <option value="no-validation">No val

However, even if the select element has a required attribute and no multiple attribute, its size is not 1:

<select class="form-control" id="validation" required>
    <option value="no-validation">No validation</option>
    <option value="simple-validation" selected>Simple Validation</option>
    <option value="recursive">Recursively validate multipart documents</option>
</select>

Am I missing something here, or did I unveil a validator bug?

astorije referenced this issue in w3c/specberus Mar 5, 2015
sideshowbarker added a commit that referenced this issue Mar 6, 2015
Addresses #47. Thanks @astorije
@sideshowbarker

This comment has been minimized.

Copy link
Member

@sideshowbarker sideshowbarker commented Mar 6, 2015

Am I missing something here, or did I unveil a validator bug?

The validator conforms to the requirements in the spec here, but the wording could be more clear. So I changed it such that the error message emitted for this case is now this:

The first child option element of a select element with a required attribute, and without a multiple attribute, and without a size attribute whose value is greater than 1, must have either an empty value attribute, or must have no text content.

Previously it wasn't clear but by “size” the message was meant to be referring to what the HTML spec more precisely calls “display size”—an abstract term of art coined in the spec to define the requirement. But in this there’s no reason it needs to state the requirement through that indirection, because it can instead be stated concretely in terms of the size attribute. So that's what I made it say now.

So I'm going to go ahead and close this out but if you believe some further fix to the validator is needed here—e.g., if you want to propose some different wording or think the validator is not actually matching the requirements in the spec here—please feel free to reopen it.

On a related note as far as the spec goes, IMHO the actual language in the spec for this requirement could be stated more precisely and clearly, so I filed a spec bug suggesting it be refined: https://www.w3.org/Bugs/Public/show_bug.cgi?id=28150

The spec currently says this:

If a select element has a required attribute specified, does not have a multiple attribute specified, and has a display size of 1, then the select element must have a placeholder label option.

And I suggested that it be changed to this:

If a select element has a required attribute specified, does not have a multiple attribute specified, and does not have a "sizes" attribute with a value greater than 1, then the select element must have a placeholder label option.

Finally, if you want an explanation of the rationale behind that particular spec requirement, Jukka’s explanation from the following e-mail message is pretty good—

https://lists.w3.org/Archives/Public/www-validator/2014Apr/0020.html

@astorije

This comment has been minimized.

Copy link
Author

@astorije astorije commented Mar 6, 2015

Hey @sideshowbarker, thanks for your answer. Detailed I must say, but I am still very confused, if not more.

To my understanding of the (suggested) spec wording and the new error message: the select element has the required attribute specified and does not have a multiple attribute specified. So I guess I meet this error because I have a "display size of 1", and I have no idea what that means...

I tried to remove the selected attribute as per Jukka's explanation but it didn't change anything. And again, my select has 3 elements, that's what I understand with "size".

@sideshowbarker

This comment has been minimized.

Copy link
Member

@sideshowbarker sideshowbarker commented Mar 7, 2015

To my understanding of the (suggested) spec wording and the new error message: the select element has the required attribute specified and does not have a multiple attribute specified. So I guess I meet this error because I have a "display size of 1", and I have no idea what that means...

@astorije Is there something unclear about the current error message shown at http://goo.gl/mjto0R ?

That error message doesn't now say anything about "display size of 1"; instead it explicitly says, without a size attribute whose value is greater than 1. Is there some way I could make that more clear?

So as far as what you'd need to do to to make your markup valid, you have two choices:

A. Use a “placeholder option label”: <option value="">Select a validation option</option>

<select class="form-control" id="validation" required>
    <option value="">Select a validation option</option>
    <option value="no-validation">No validation</option>
    <option value="simple-validation" selected>Simple Validation</option>
    <option value="recursive">Recursively validate multipart documents</option>
</select>

B. Use a size attribute with the appropriate value:
<select class="form-control" id="validation" required size=3>

<select class="form-control" id="validation" required size=3>
    <option value="no-validation">No validation</option>
    <option value="simple-validation" selected>Simple Validation</option>
    <option value="recursive">Recursively validate multipart documents</option>
</select>

The choice just depends on what you prefer to show to the user in the UI: either a normal select drop-down menu, or a 3-row multi-select list box.

I think most people go with the normal select drop-down menu, which is why the spec tries to help here by requiring a “placeholder option label” for this case.

Do you have some suggestion about how I could change the wording of the error message to help users understand that the two solutions are A and B above? Or maybe @Hixie has a suggestion.

sideshowbarker added a commit that referenced this issue Mar 7, 2015
Addresses #47. Thanks again @astorije
@sideshowbarker

This comment has been minimized.

Copy link
Member

@sideshowbarker sideshowbarker commented Mar 7, 2015

OK I added some clarifying text to the error message such that it now also says, “Consider either adding a placeholder option label, or adding a size attribute with a value equal to the number of option elements.” Further feedback/suggestions on improving the message here at still much welcome.

kurosawa-takeshi added a commit to kurosawa-takeshi/validator that referenced this issue Mar 9, 2015
kurosawa-takeshi added a commit to kurosawa-takeshi/validator that referenced this issue Mar 9, 2015
stlk added a commit to stlk/django that referenced this issue Nov 5, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 5, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 5, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 5, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 6, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 6, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 8, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 11, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
stlk added a commit to stlk/django that referenced this issue Nov 11, 2016
Fixed issue where we caused HTML to be invalid by specifying required
on select field with nonempty first value.

validator/validator#47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.