I've got a custom datepicker widget which I want to validate using jQuery.validate. When I modify my date it doesn't revalidate, presumably because the change event isn't firing on underlying hidden to which jQuery.validate is bound.
Through my research I've found that I can revalidate a single field by calling $('#mydatepicker').valid()
. I can put this in the on-change handler of my custom widget.
In theory, this should work, but my widget's on-change event fires once before jQuery.validation is initialized. This seems to break jQuery.validate completely.
So I'm looking for a way to determine if jQuery.validate has been initialized for this particular element. i.e., to determine if jQuery.validate is attempting to watch it.
I tried
if($input.valid) $input.valid();
But I think the method exists regardless if jQuery.validate has been initialized yet.
To be clear, the structure of my HTML looks like this:
<form id="myform">
<input id="mywidget" type="hidden">
<script>$('#mywidget').initializeMyCustomWidget();</script>
</form>
<script>
$('#myform').validate({ myOptions });
</script>
You cannot use
.valid()
before.validate()
is initialized.However, since one would typically initialize
.validate()
on DOM ready, this should never be an issue.Documentation states:
Simply initialize the plugin on DOM ready so it can "watch" the form for triggering events.