Add generic ajax error catcher for status code 500
This commit is contained in:
parent
3ff7765d6c
commit
900471be54
31 changed files with 463 additions and 502 deletions
14
public/assets/js/common.js
Normal file
14
public/assets/js/common.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
$(function() {
|
||||||
|
$(document).ajaxError(function(event, response, ajaxSettings, thrownError) {
|
||||||
|
switch (response.status) {
|
||||||
|
case 500:
|
||||||
|
default:
|
||||||
|
swal({
|
||||||
|
title: 'Whoops!',
|
||||||
|
text: 'We encountered a problem. Please contact technical support.',
|
||||||
|
type: 'error'
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -694,6 +694,7 @@
|
||||||
<!--end::Page Vendors -->
|
<!--end::Page Vendors -->
|
||||||
<!--begin::Page Snippets -->
|
<!--begin::Page Snippets -->
|
||||||
<script src="/assets/app/js/dashboard.js" type="text/javascript"></script>
|
<script src="/assets/app/js/dashboard.js" type="text/javascript"></script>
|
||||||
|
<script src="/assets/js/common.js" type="text/javascript"></script>
|
||||||
<!--end::Page Snippets -->
|
<!--end::Page Snippets -->
|
||||||
|
|
||||||
<!--begin::Extra Scripts -->
|
<!--begin::Extra Scripts -->
|
||||||
|
|
|
||||||
|
|
@ -86,38 +86,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -86,38 +86,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -86,38 +86,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -264,38 +264,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -171,12 +171,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -369,99 +369,101 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var json = response.responseJSON;
|
if (response.status == 422) {
|
||||||
var errors = json.errors;
|
var json = response.responseJSON;
|
||||||
var nerrors = json.nerrors;
|
var errors = json.errors;
|
||||||
var verrors = json.verrors;
|
var nerrors = json.nerrors;
|
||||||
var firstfield = false;
|
var verrors = json.verrors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[data-name='" + field + "']");
|
var formfield = $("[data-name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
|
||||||
formfield.addClass('form-control-danger');
|
|
||||||
label.addClass('has-danger');
|
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
|
||||||
var domfield = formfield.get(0);
|
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
|
||||||
firstfield = domfield;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add error class to this tab
|
|
||||||
var tabId = $(formfield).closest('.tab-pane').prop('id');
|
|
||||||
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
|
||||||
});
|
|
||||||
|
|
||||||
// loop through mobile number errors
|
|
||||||
$.each(nerrors, function(rowindex, errorlist) {
|
|
||||||
var row = $("#data-mobile-numbers table").find("[name='index'][value='" + rowindex + "']").closest('tr');
|
|
||||||
|
|
||||||
$.each(errorlist, function(field, msg) {
|
|
||||||
var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
|
|
||||||
var col = msgbox.closest('span');
|
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
col.addClass('has-danger');
|
formfield.addClass('form-control-danger');
|
||||||
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = col.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add error class to this tab
|
// add error class to this tab
|
||||||
var tabId = $(col).closest('.tab-pane').prop('id');
|
var tabId = $(formfield).closest('.tab-pane').prop('id');
|
||||||
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// loop through vehicle errors
|
// loop through mobile number errors
|
||||||
$.each(verrors, function(rowindex, errorlist) {
|
$.each(nerrors, function(rowindex, errorlist) {
|
||||||
var row = $("#data-vehicles table").find("[name='index'][value='" + rowindex + "']").closest('tr');
|
var row = $("#data-mobile-numbers table").find("[name='index'][value='" + rowindex + "']").closest('tr');
|
||||||
|
|
||||||
$.each(errorlist, function(field, msg) {
|
$.each(errorlist, function(field, msg) {
|
||||||
var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
|
||||||
var col = msgbox.closest('span');
|
var col = msgbox.closest('span');
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
col.addClass('has-danger');
|
col.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = col.get(0);
|
var domfield = col.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add error class to this tab
|
// add error class to this tab
|
||||||
var tabId = $(col).closest('.tab-pane').prop('id');
|
var tabId = $(col).closest('.tab-pane').prop('id');
|
||||||
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// focus on tab containing first field
|
// loop through vehicle errors
|
||||||
var firstTabId = $(firstfield).closest('.tab-pane').prop('id');
|
$.each(verrors, function(rowindex, errorlist) {
|
||||||
$("#customer-tabs").find("a[href='#" + firstTabId + "']").tab('show');
|
var row = $("#data-vehicles table").find("[name='index'][value='" + rowindex + "']").closest('tr');
|
||||||
|
|
||||||
// focus on first bad field
|
$.each(errorlist, function(field, msg) {
|
||||||
firstfield.focus();
|
var msgbox = row.find(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
var col = msgbox.closest('span');
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// add error classes to bad fields
|
||||||
$('html, body').animate({
|
col.addClass('has-danger');
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
}, 100);
|
|
||||||
|
// check if this field comes first in DOM
|
||||||
|
var domfield = col.get(0);
|
||||||
|
|
||||||
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
|
firstfield = domfield;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add error class to this tab
|
||||||
|
var tabId = $(col).closest('.tab-pane').prop('id');
|
||||||
|
$("#customer-tabs").find("a[href='#" + tabId + "']").addClass('has-danger');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// focus on tab containing first field
|
||||||
|
var firstTabId = $(firstfield).closest('.tab-pane').prop('id');
|
||||||
|
$("#customer-tabs").find("a[href='#" + firstTabId + "']").tab('show');
|
||||||
|
|
||||||
|
// focus on first bad field
|
||||||
|
firstfield.focus();
|
||||||
|
|
||||||
|
// scroll to above that field to make it visible
|
||||||
|
$('html, body').animate({
|
||||||
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,12 +192,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -269,38 +269,40 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,12 +154,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -698,38 +698,40 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "'], [data-name='" + field + "']");
|
var formfield = $("[name='" + field + "'], [data-name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -248,38 +248,40 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,12 +158,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -114,38 +114,40 @@ $(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,12 +146,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -169,38 +169,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -161,12 +161,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -116,38 +116,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,12 +133,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -138,38 +138,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,12 +163,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -184,38 +184,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,12 +165,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -86,38 +86,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -122,38 +122,40 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).fail(function(response) {
|
}).fail(function(response) {
|
||||||
var errors = response.responseJSON.errors;
|
if (response.status == 422) {
|
||||||
var firstfield = false;
|
var errors = response.responseJSON.errors;
|
||||||
|
var firstfield = false;
|
||||||
|
|
||||||
// remove all error classes first
|
// remove all error classes first
|
||||||
removeErrors();
|
removeErrors();
|
||||||
|
|
||||||
// display errors contextually
|
// display errors contextually
|
||||||
$.each(errors, function(field, msg) {
|
$.each(errors, function(field, msg) {
|
||||||
var formfield = $("[name='" + field + "']");
|
var formfield = $("[name='" + field + "']");
|
||||||
var label = $("label[data-field='" + field + "']");
|
var label = $("label[data-field='" + field + "']");
|
||||||
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
var msgbox = $(".form-control-feedback[data-field='" + field + "']");
|
||||||
|
|
||||||
// add error classes to bad fields
|
// add error classes to bad fields
|
||||||
formfield.addClass('form-control-danger');
|
formfield.addClass('form-control-danger');
|
||||||
label.addClass('has-danger');
|
label.addClass('has-danger');
|
||||||
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
msgbox.html(msg).addClass('has-danger').removeClass('hide');
|
||||||
|
|
||||||
// check if this field comes first in DOM
|
// check if this field comes first in DOM
|
||||||
var domfield = formfield.get(0);
|
var domfield = formfield.get(0);
|
||||||
|
|
||||||
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
if (!firstfield || (firstfield && firstfield.compareDocumentPosition(domfield) === 2)) {
|
||||||
firstfield = domfield;
|
firstfield = domfield;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// focus on first bad field
|
// focus on first bad field
|
||||||
firstfield.focus();
|
firstfield.focus();
|
||||||
|
|
||||||
// scroll to above that field to make it visible
|
// scroll to above that field to make it visible
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: $(firstfield).offset().top - 200
|
scrollTop: $(firstfield).offset().top - 200
|
||||||
}, 100);
|
}, 100);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,12 +145,6 @@
|
||||||
}).done(function(response) {
|
}).done(function(response) {
|
||||||
table.row(btn.parents('tr')).remove();
|
table.row(btn.parents('tr')).remove();
|
||||||
table.reload();
|
table.reload();
|
||||||
}).fail(function() {
|
|
||||||
swal({
|
|
||||||
title: 'Whoops',
|
|
||||||
text: 'An error occurred while deleting this item. Please contact support.',
|
|
||||||
type: 'error'
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue