angular-ui / ui-select

AngularJS-native version of Select2 and Selectize
MIT License
3.26k stars 1.82k forks source link

AngularJS form validation #556

Open YanBlochSergata opened 9 years ago

YanBlochSergata commented 9 years ago

Hey all,

I'm trying to add required to my "ui-select multiple" element, but no success so far.

I tried adding "required" to the input that generates from the directive, but the input doesn't recognize the selections, it keeps being invalid.

MikeABentley commented 9 years ago

+1

dannystyleart commented 9 years ago

Hey all!

We've just found that the input that the directive renders has no name attribute, and while this the form validation throws error since can't validate the value of the ui-select.

Did anyone worked out this? Thanks,

MikeABentley commented 9 years ago

Can you elaborate on what sort of validation you're trying to accomplish? Sample code as well? thanks.

dannystyleart commented 9 years ago

@MBentley1976 Yeah, we are using Valdr to validate our forms. we tried to not to make rules / constraints on the model which the ui-select using but since ui-select creates an input inside it ( so inside the form ) valdr tries to fetch it and attach its own validation object(s). It dies since the input has no name attribute.

MikeABentley commented 9 years ago

I see. Well, I'm not familiar with Valdr but one workaround you may want to try is to create an extension to the ui-select directive. In that extension you can use jquery; either native or the angular wrapped up version, to sniff out the input and add the name attribute yourself. By using an extension you'll get the functionality "for free" everywhere. Good luck.