guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.04k stars 1.31k forks source link

What about select validation ? #38

Closed bendem closed 11 years ago

bendem commented 11 years ago

Hi guy, at first, thanks for this awesome jQuery plugin...

I tried to make sure that the first option of my select will not passed (it's something to say user to choose an option...) so i put an empty value and tried "data-notblank", "required", "data-regexp" but nothing seems to work at the moment.

I looked in the code but i don't understand all of it ;) is there a simple way to do that ?

Cordially,

guillaumepotier commented 11 years ago

It might be a bug. I did not tested required on select in my test suite.

Could you copy / paste your code / jsfiddle it?

Best

sylouuu commented 11 years ago

It works if you put data-required="true" inside the select tag, however you have to get at least one option tag or you'll get an error like "xxx length of null".

bendem commented 11 years ago

Sorry, it works if you put a empty value and data-required="true" in the select tag... But in fact, the state of the select does not update when changing value like other inputs but when submiting the form again.

guillaumepotier commented 11 years ago

Please, try to add data-trigger="change" to trigger a new validation on each select option change.

sylouuu commented 11 years ago

Like a green background he would say imo.

noahlh commented 11 years ago

Also, when you say "state of the select does not update" be aware that the CSS options for select tags are more limited than other input tags, so the issue might be with your CSS styling.

I use the following library to "normalize" select tags and make them behave like other tags (fully customizable) and they work well with parseley with a few tweaks:

http://adam.co/lab/jquery/customselect/

If anyone decides to implement this, post up and I'll share the customizations I did...

bendem commented 11 years ago

My css work fine, and the data-trigger="change" too... Thanks for that reactivity ;-)

guillaumepotier commented 11 years ago

Great!

I'll try to add a checkbox example in the demo form on documentation.

Best

[EDIT] keep this issue open until there's the demo on the doc ;)

dotcominfo commented 11 years ago

I just ran into this. Followed the things discussed here but no luck with validation on the select field. I'm using a dropdown for a State selection, and in the select tag I have: data-required="true" data-trigger="change"

calvinlloyd commented 11 years ago

@noahlh can you please post your custom select + parsley integration?

com-ethode-jables commented 10 years ago

@dotcominfo I was running into this issue when using a placeholder as the first option. For example, if you have a dropdown of US states and the first option is something like:

<option>Select a state...</option>

, you need to make sure to explicitly set the value as empty for that first option, e.g.:

<option value="">Select a state...</option>

. Once I did that, the validation worked as expected, meaning the error message was displayed if the default placeholder was selected, and not an actual US state option. For what it's worth, I also used parsely-required="true" and data-trigger="change" on the select tag.

radhamanis commented 6 years ago

I am using nice select dropdown to customize the select tag. Parsley is not validating with select dropdown when we are using nice select. Please suggest a solution how to use nice select with parsley.

chandru1822 commented 6 years ago

I am using nice select dropdown to customize the select tag. Parsley is not validating with select dropdown when we are using nice select. Please suggest a solution how to use nice select with parsley.

SimonFricker commented 5 years ago

+1

nadnadia96 commented 4 years ago

I am using selectric dropdown. Parsley is not validating with select dropdown when using selectric class. Please suggest a solution how to use selectric class with parsley validation.

marcandre commented 4 years ago

Config probably needs to be tweaked, since by default Parsley will exclude hidden fields.

If someone needs me to spend time writing a complete solution I'm available for hire.

PranayHalder commented 4 years ago

@dotcominfo I was running into this issue when using a placeholder as the first option. For example, if you have a dropdown of US states and the first option is something like:

<option>Select a state...</option>

, you need to make sure to explicitly set the value as empty for that first option, e.g.:

<option value="">Select a state...</option>

. Once I did that, the validation worked as expected, meaning the error message was displayed if the default placeholder was selected, and not an actual US state option. For what it's worth, I also used parsely-required="true" and data-trigger="change" on the select tag.

This works Perfectly. THanks