问题
I'm trying to make myself a form, but I need to prevent some UX stuff depending on if a form was entered correctly. Is there an api for manually issuing the validation routine to a form's field? I know that I could listen to the post-validation events, but I actually need to start the validation from an external source.
Is this possible?
回答1:
You can dispatch a change event to the form with jQuery: $("#myForm").trigger("change");
It will trigger validation.
回答2:
The accepted trigger on the form did not work for me. Instead using $('#myForm').submit()
successfully triggers the checks manually. If you're using an asynchronous form you would just need to do the right preventDefault
and return false
on the form so that it does not submit like a normal form. I solved this by adding a universal class / data-attribute called data-ajax-submit
or ajax-submit
for my forms.
回答3:
Based on the code from Foundation 5.5.3 you can try this one:
$('#my_form').trigger('validate.fndtn.abide');
来源:https://stackoverflow.com/questions/27487823/manually-triggered-abide-validation-in-zurb-foundation