Allow Ajax Validation errors in Frontend.js

For some odd reason, this was left out of the frontend, but implemented in App.js and Backend.js
This commit is contained in:
JapSeyz 2016-06-15 20:49:44 +02:00
parent bc6232c520
commit 9841233d64
1 changed files with 29 additions and 0 deletions

View File

@ -3923,6 +3923,13 @@ function log() {
},
error: function(data, statusText, xhr, $form) {
$submitButton = $form.find('input[type=submit]');
// Form validation error.
if (422 == data.status) {
processFormErrors($form, $.parseJSON(data.responseText));
return;
}
toggleSubmitDisabled($submitButton);
showMessage('Whoops!, it looks like something went wrong on our servers.\n\
Please try again, or contact support if the problem persists.');
@ -4181,6 +4188,28 @@ $.extend(
}
});
function processFormErrors($form, errors)
{
$.each(errors, function (index, error)
{
var $input = $(':input[name=' + index + ']', $form);
if ($input.prop('type') === 'file') {
$('#input-' + $input.prop('name')).append('<div class="help-block error">' + error + '</div>')
.parent()
.addClass('has-error');
} else {
$input.after('<div class="help-block error">' + error + '</div>')
.parent()
.addClass('has-error');
}
});
var $submitButton = $form.find('input[type=submit]');
toggleSubmitDisabled($submitButton);
}
/*!
* Smooth Scroll - v1.4.13 - 2013-11-02
* https://github.com/kswedberg/jquery-smooth-scroll