I'm trying to perform client side validation using jquery.validate.js on a form submitted via Ajax (using form actions), but for some reason, the client side validation is not being triggered.
This is what I have in my template.php file in order to trigger an ajax call for login:
$form['actions']['submit']['#ajax'] = array(
'callback' => 'fantasia_user_login_ajax_callback',
'wrapper' => 'user-login-form',
'event' => 'mousedown',
);
And here's my js to trigger the client side validation:
(function ($) {
Drupal.loginAjax = {
form_id: 'user-login-form'
};
Drupal.behaviors.loginAjax = {
attach: function (context ,settings) {
Drupal.loginAjax.beforeSubmit = function (form_values, form, options) {
$("form#user-login-form", context).validate({
rules: {
edit_pass: "required",
edit_name: "required"
},
messages: {
edit_name: {
required: "E-mail Address is required"
}
}
});
}
for (ajax_el in settings.ajax) {
if (Drupal.ajax[ajax_el].element.form) {
if (Drupal.ajax[ajax_el].element.form.id == Drupal.loginAjax.form_id) {
Drupal.ajax[ajax_el].beforeSubmit = Drupal.loginAjax.beforeSubmit;
}
}
}
}
};
})(jQuery);
The beforeSubmit method is being triggered because when I print to the console, I do get a value.
On a sidenote, I've tried doing this using the beforeSend instead. The client side validation does trigger, but the submit is not being halted.
Any pointers please?