victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 476 forks source link

Remove option selected of the select2, not auto validator #648

Open vqquoc opened 6 years ago

vqquoc commented 6 years ago

I'm using select2 with addValidator "required_select", when I remove the selected option, it stays in the state of success. I want to display the error immediately after removing the option

I haved add a custom validator:

    //Add custom validator

$.formUtils.addValidator({ name : 'required_select', validatorFunction : function(value, $el, config, language, $form) { return value !== ''; }, errorMessage : 'Field is required', errorMessageKey: 'badSelectRequired' })

    //Init select2

var sl = $("#region").select2({ placeholder: "Please select a region", allowClear: true, containerCssClass: 'form-control' }); //Get event selected sl.on("select2:select", function(e) { sl.validate({ validateHiddenInputs: false });//Selected - Hide errors message }); //Get event remove option selected sl.on("select2:unselecting", function(e) { //Show message required (how to recall the error display) })

Thanks!