Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions js/jquery.validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,18 @@
$element.removeClass('invalid');
}
});

// Show messages if action redirect is not given
if (response.message && (!response.action || !response.action.redirect) ) {
var showMessages = true;
if ( response.action && response.action.redirect ) {
// don't show messages if redirect action was given
showMessages = false;
}
if ( response.action && response.action.resubmit && $form.data('resubmit-disabled')!==true ) {
// don't show messages if resubmit action was given and resubmission has not been disabled
showMessages = false;
}
if ( showMessages && response.message ) {
$.each(response.message, function(type, object) {
$form.validation('showMessage', type, object.value);
// Compare message to highest element on page
Expand All @@ -198,6 +207,12 @@
}

if ( response.status === 'valid' ) {
// submission was valid

// re-enable future resubmit actions
$form.data('resubmit-disabled',false);

// redirect action
if ( response.action && response.action.redirect ) {
// Redirect if record was valid and the redirect action was given
window.location.href = response.action.redirect.value;
Expand All @@ -208,6 +223,20 @@
$form.off('submit.validate').submit();
return;
}
} else {
// submission was invalid

// resubmit action - used for authenticity token errors
if ( response.action && response.action.resubmit && $form.data('resubmit-disabled')!==true ) {
// resubmit the form
$form.submit();
// disable future resubmit actions to prevent inifite loop
$form.data('resubmit-disabled',true);
return;
} else {
// re-enable future resubmit actions
$form.data('resubmit-disabled',false);
}
}

// Scroll to the element if there is one to scroll to
Expand Down Expand Up @@ -378,4 +407,4 @@

});

})(jQuery, window, document);
})(jQuery, window, document);