ginader / HTML5-placeholder-polyfill

Small and robust polyfill for the HTML5 placeholder attribut.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

label should not be required

iamnoah opened this issue · comments

While I understand the desire to ensure screen readers are taken care of, it isn't really the job of a polyfill to enforce best practices. There exist valid use cases for an input without a label, and requiring a label keeps this from being a completely usable polyfill.

If the label is not present, the placeholder can be appended to the input's parent.

I agree, it might not be the job of a polyfill to enforce best practices but I strongly believe it's my job.
As I see no reason ever to have a input or textarea element without a label I will not change this.
Thanks for your contribution though. The new Version 1.3 including your previous changes just went live.

I think labels should be required. That's one of the things that makes this script awesome!

thanks scruffian. Much appreciated :-)

Labels need not be required. For example, I work for a company that does build outs for a design agency that often prefers to simply have placeholders instead of labels. Rather than put an empty label in my HTML, we added this before line 89 of the JS source:

if ($('label[for='+id+']').length == 0) {
    $('<label for="'+id+'"]></label>').insertBefore(this);
}

This dynamically injects a blank label into the DOM that can then be used to position the placeholder. It also checks to make sure a label doesn't already exist.

Not having Labels is a SERIOUS accessibility issue. What you're suggesting is a very bad practice.
Placeholders are no replacement for the label!

I recommend writing a proper label and hiding it offscreen with the class the script includes (see the examples page).
That's what I'm doing. Best of both worlds.

Thanks for your reply. I must have missed the offscreen class (label.visuallyhidden-with-placeholder) in the examples, but after using it I see that it works quite well. Thanks for bringing it to my attention. I have gone back in and added labels into my current project because I do agree with you it is an accessibility issue. However, if anyone really feels that they don't want to have to add labels into a site and still have your polyfill work (for example, if someone were retrofitting a large project written with tons of placeholders) there is a way around it. Not best practice by any stretch though.

In any case, thanks for a great plugin - it's working really well.

I'm very happy to hear that Louis. Thanks for the great feedback :-)