Athan Clark
Athan Clark

Reputation: 3970

Manually triggered Abide validation in Zurb Foundation

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?

Upvotes: 1

Views: 4050

Answers (3)

claudiu.f.marginean
claudiu.f.marginean

Reputation: 134

Based on the code from Foundation 5.5.3 you can try this one:

$('#my_form').trigger('validate.fndtn.abide');

Upvotes: 0

Cayce K
Cayce K

Reputation: 2338

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.

Upvotes: 0

JAre
JAre

Reputation: 4756

You can dispatch a change event to the form with jQuery: $("#myForm").trigger("change");
It will trigger validation.

Upvotes: 2

Related Questions