This commit is contained in:
2019-04-08 20:53:38 +00:00
parent c36fb3dd17
commit fda9dcddda
3 changed files with 40 additions and 18 deletions

View File

@@ -3,6 +3,8 @@
// GZVALIDATE
//
// provides form validation services
// and also general error display in forms
//probably should be broken up more
// All locale keys for validation *MUST* be fetched prior to this being used as it assumes all keys are fetched first
// Add any new keys used to the block in locale.js=>commonKeysEditForm
@@ -92,17 +94,29 @@ function getErrorsForField(v, ref) {
///////////////////////////////
// ERROR BOX ERRORS
// gathers any messages for error box on form which is the generic catch all for non field specific errors from server
// and application itself locally
function GetErrorBoxErrors(v, errs) {
if (errs.length < 1) {
return null;
var hasErrors = false;
var ret = "";
if (errs.length > 0) {
hasErrors = true;
//loop array and append each error to a return string
for (var i = 0; i < errs.length; i++) {
ret += errs[i] + "\r\n";
}
}
var ret = "";
//loop array and append each error to a return string
for (var i = 0; i < errs.length; i++) {
ret += errs[i] + "\r\n";
//any application errors?
if (v.appError) {
hasErrors = true;
ret = v.appError + "\r\n----------\r\n" + ret;
}
if (!hasErrors) {
return null;
} else {
return ret;
}
return ret;
}
export default {
@@ -265,6 +279,11 @@ export default {
throw "DEV ERROR gzvalidate::ServerErrors -> serverError seems to be missing from form's vue data object";
}
//make sure appError is defined on data
if (!v.$_.has(v, "appError")) {
throw "DEV ERROR gzvalidate::ServerErrors -> appError seems to be missing from form's vue data object";
}
//make sure errorBoxMessage is defined on data
if (!v.$_.has(v, "errorBoxMessage")) {
throw "DEV ERROR gzvalidate::ServerErrors -> errorBoxMessage seems to be missing from form's vue data object";
@@ -330,17 +349,19 @@ export default {
///////////////////////////////
// ClearServerErrors
// Clear all server errors and ensure error box doesn't show and validation is triggered
ClearServerErrors(v) {
// Clear all server errors and app errors and ensure error box doesn't show
DeleteAllErrorBoxErrors(v) {
//clear all keys from server error
v.$gzutil.RemoveAllPropertiesFromObject(v.serverError);
//clear app errors
v.appError = null;
//clear out actual message box display
v.errorBoxMessage = null;
},
///////////////////////////////
// SetErrorBoxErrors
// Gather server errors and set the appropriate keys
SetErrorBoxErrors(v) {
//maybe just put all the code in here and don't call geterrorboxerrors at all as no one else will need to call it anyway
var errs = this.ServerErrors(v, "errorbox");
var ret = GetErrorBoxErrors(v, errs);
v.errorBoxMessage = ret;
@@ -363,7 +384,8 @@ export default {
//If there are no more errors in details then remove the whole thing as it's no longer required
if (v.serverError.details && v.serverError.details.length < 1) {
if (v.serverError.code == "2200") {
this.ClearServerErrors(v);
//clear all keys from server error
v.$gzutil.RemoveAllPropertiesFromObject(v.serverError);
}
}