jQuery Validate - Enable validation for hidden fields

后端 未结 9 1909
忘了有多久
忘了有多久 2020-11-21 22:27

In the new version of jQuery validation plugin 1.9 by default validation of hidden fields ignored. I\'m using CKEditor for textarea input field and it hides the field and re

9条回答
  •  我在风中等你
    2020-11-21 23:01

    The validation was working for me on form submission, but it wasn't doing the reactive event driven validation on input to the chosen select lists.

    To fix this I added the following to manually trigger the jquery validation event that gets added by the library:

    $(".chosen-select").each(function() {
      $(this).chosen().on("change", function() {
        $(this).parents(".form-group").find("select.form-control").trigger("focusout.validate");
      });
    });
    

    jquery.validate will now add the .valid class to the underlying select list.

    Caveat: This does require a consistent html pattern for your form inputs. In my case, each input filed is wrapped in a div.form-group, and each input has .form-control.

提交回复
热议问题