jQuery validate - unhighlight function not working for hidden element (selectize.js)

六月ゝ 毕业季﹏ 提交于 2020-06-29 03:50:09

问题


The form below contains a selectize input and a submit button:

The selectize is a required field, so if the selectize is empty when the form is submitted an error message is shown:

Here is the JSFiddle.

The problem is that the error message is visible even after the user has selected an option.

jQuery validate ignores hidden elements by default so to get it to work on the selectize (the tag is hidden when selectize.js initialises), I initialised it with the option ignore: :not(.selectized).

This seems to work for lazy validation of the form (submitting the form when the input is empty triggers the error message to be displayed above it) but not for eager validation because the message still persists after the field has been filled in.

EDIT: Maybe it has something to do with the selectize input not triggering any of the events (onfocusout, onkeyup, onclick) that the plugin listens to for eager validation of an input? It works if I force validation using

$('.selectized').on('change', function() {

    $(this).valid();

})

but this seems like a hack.

来源:https://stackoverflow.com/questions/62607683/jquery-validate-unhighlight-function-not-working-for-hidden-element-selectize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!