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

HTML5 required attribute #54

Open
andre-f-paggi opened this issue Mar 13, 2017 · 2 comments
Open

HTML5 required attribute #54

andre-f-paggi opened this issue Mar 13, 2017 · 2 comments

Comments

@andre-f-paggi
Copy link

Hi,

I usually use this library extension in my project's forms and I want to use the HTML5 required attribute to validate if my select is fulfilled correctly. I tried putting it on the select2 tag, but didn't work as expected.

Is there support for it? If not, can I make a PR with this improvement?

Thanks for this awesome library.

@rubenv
Copy link
Owner

rubenv commented Mar 13, 2017

can I make a PR with this improvement

Certainly! Always welcome!

@andre-f-paggi
Copy link
Author

Well, I discovered that the select2 directive does transfer the attributes to the internal input hidden field, even the required attribute.
The problem is that the HTML5 specification does not validate hidden fields.

I got what I wanted with these lines of code:

if(attrs.required){
   element[0].style = "display:visible; position:absolute; clip:rect(0,0,0,0);";
   element[0].type = "text";
}

But I don't know about HTML5 semantics, acessibility and I dont think it was an elegant solution. Because of that, I don't think that this may be useful for this project and maybe I will do this only on my company's project, because there is no rule there. 😁

I will study more about this difficulty and about this project's code.

Thanks for your time.

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

No branches or pull requests

2 participants