jQuery-Form-Validator
jQuery-Form-Validator copied to clipboard
Remove option selected of the select2, not auto validator
trafficstars
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!