How to make select2 work with jquery.validation plugin?

后端 未结 15 622
北荒
北荒 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:39

    I've found that getting Select2 to work with jQuery Validate very much depends on the markup used in creating the Select2 control.

    For the most practical use of the plugin, you'll probably be using dynamically loaded data (data obtained via web service vs. static elements in the page). And per their spec, the way to accomplish this is by attaching Select2 to an element. However, elements of type="hidden" are not validated by jQuery Validate by default.

    In order to validate hidden elements using jQuery Validate, one must tinker with the ignore property in jQuery Validate's configuration object. See the ignore option in their spec. Try initializing the ignore value as null to get the validation to trigger.

提交回复
热议问题