diff --git a/public/assets/javascript/app-public.js b/public/assets/javascript/app-public.js
index 4e84a41e..a4638b0c 100644
--- a/public/assets/javascript/app-public.js
+++ b/public/assets/javascript/app-public.js
@@ -20,6 +20,13 @@ $(function() {
},
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.');
@@ -167,6 +174,30 @@ $(function() {
});
+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('
' + error + '
')
+ .parent()
+ .addClass('has-error');
+ } else {
+ if($input.parent().hasClass('input-group')) {
+ $input = $input.parent();
+ }
+
+ $input.after('' + error + '
')
+ .parent()
+ .addClass('has-error');
+ }
+ });
+
+ var $submitButton = $form.find('input[type=submit]');
+ toggleSubmitDisabled($submitButton);
+}
/**
* Toggle a submit button disabled/enabled - duh!
@@ -202,6 +233,9 @@ function clearFormErrors($form) {
$($form).find(':input')
.parent()
.removeClass('has-error');
+ $($form).find(':input')
+ .parent().parent()
+ .removeClass('has-error');
}
function showFormError($formElement, message) {
diff --git a/public/assets/javascript/frontend.js b/public/assets/javascript/frontend.js
index e140b4b7..ae0bba96 100644
--- a/public/assets/javascript/frontend.js
+++ b/public/assets/javascript/frontend.js
@@ -3926,8 +3926,8 @@ function log() {
// Form validation error.
if (422 == data.status) {
- processFormErrors($form, $.parseJSON(data.responseText));
- return;
+ processFormErrors($form, $.parseJSON(data.responseText));
+ return;
}
toggleSubmitDisabled($submitButton);
@@ -4077,6 +4077,30 @@ function log() {
});
+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('' + error + '
')
+ .parent()
+ .addClass('has-error');
+ } else {
+ if($input.parent().hasClass('input-group')) {
+ $input = $input.parent();
+ }
+
+ $input.after('' + error + '
')
+ .parent()
+ .addClass('has-error');
+ }
+ });
+
+ var $submitButton = $form.find('input[type=submit]');
+ toggleSubmitDisabled($submitButton);
+}
/**
* Toggle a submit button disabled/enabled - duh!
@@ -4115,7 +4139,6 @@ function clearFormErrors($form) {
$($form).find(':input')
.parent().parent()
.removeClass('has-error');
-
}
function showFormError($formElement, message) {
@@ -4192,32 +4215,6 @@ $.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('' + error + '
')
- .parent()
- .addClass('has-error');
- } else {
- if($input.parent().hasClass('input-group')) {
- $input = $input.parent();
- }
-
- $input.after('' + error + '
')
- .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