Choices-js / Choices

A vanilla JS customisable select box/text input plugin ⚡️
https://choices-js.github.io/Choices/
MIT License
6.14k stars 606 forks source link

How to validate select? #90

Closed lavezzi1 closed 7 years ago

lavezzi1 commented 7 years ago

Hello,

Can I validate your select using plugins like https://github.com/ansman/validate.js or https://github.com/skaterdav85/validatorjs ?

Or maybe you recommend something different. I just need to validate select on empty value, if nothing change then show error.

jshjohnson commented 7 years ago

Hi @lavezzi1,

Could you perhaps give me a code example of how you would like to validate? Would it be when the user types?

There is callbackOnChange method that is useful for validation. Example:

var example = new Choices(element, {
  callbackOnChange: function(value) {
    if(!value) {
      // handle error
    } else {
      // handle success
    }
  }
});