How to make select2 work with jquery.validation plugin?

后端 未结 15 592
北荒
北荒 2020-12-01 02:40

I\'m trying to validate select2 field using jquey.validation plugin but nothing happens.

I want to make select required field.

I\'m using this custom validat

15条回答
  •  不思量自难忘°
    2020-12-01 03:25

    As a tip, please consider that the validate js bind itself to changes of select not select 2. This cause problem in below case:

    1. There is a required select box which is converted to select2
    2. You click the submit and the error shows that the select box is required.
    3. You select some option from select 2.
    4. The validation error does not hide automatically

    You can fix it with:

         $("select").on("select2:close", function (e) {  
            $(this).valid(); 
        });
    

提交回复
热议问题