Skip to content

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

@vqquoc

Description

@vqquoc

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!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions