angular-select2 icon indicating copy to clipboard operation
angular-select2 copied to clipboard

HTML5 required attribute

Open andre-f-paggi opened this issue 8 years ago • 2 comments
trafficstars

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.

andre-f-paggi avatar Mar 13 '17 14:03 andre-f-paggi

can I make a PR with this improvement

Certainly! Always welcome!

rubenv avatar Mar 13 '17 14:03 rubenv

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.

andre-f-paggi avatar Mar 13 '17 23:03 andre-f-paggi