This commit is contained in:
2019-04-04 17:05:33 +00:00
parent 35f2757e94
commit 8f6887d5f3
3 changed files with 45 additions and 25 deletions

View File

@@ -11,6 +11,8 @@
//import _ from "../libs/lodash.min.js";
import errorHandler from "./errorhandler";
var triggeringChange = false;
function isEmpty(o) {
if (typeof o == "number" && o == 0) {
return false;
@@ -472,24 +474,44 @@ Here are all the API level error codes that can be returned by the API server:
// On Change handler
// This is required so that server errors can be cleared when input is changed
Change(v, ref) {
if (triggeringChange) {
return;
}
//If ref appears in the servererrors details collection, remove each one
var m = v.$_.remove(v.serverError.details, function(o) {
return o.target == ref;
});
// //if a target was hit then need to trigger validate again for it to remove the error message
//NOTHING SEEMS TO BE ABLE TO TRIGGER THIS
// if (m.length > 0) {
// var ctrl = getControl(v, ref);
// //ctrl.validate(true);
// // ctrl.errorMessages.length=0;
// // var frm=getControl(v,"form");
// // frm.validate();
// }
//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.RemoveAllProperties(v.serverError);
}
}
//Clear out old validation display in form by forcing the control's data to change
//I tried calling form validate and reset and all that bullshit but it did nothing
//probably because it has safeguards to prevent excess validation, this works though so far
//I added the triggering change guard but it actually doesn't seem to be required here, more investigation is required
if (m.length > 0) {
triggeringChange = true;
var val = v.obj[ref];
v.obj[ref] = null;
v.obj[ref] = val;
triggeringChange = false;
}
},
///////////////////////////////
// Clean out server errors
// This is called both from the form immediately before submit and here in Change handler
// It's purpose is to more efficiently clear out the object even though I could set it to an empty object, this way it just keeps the same object
// avoiding some potential issues
RemoveAllProperties(o) {
//clear any errors that might be around from previous submit
for (var variableKey in o) {
if (o.hasOwnProperty(variableKey)) {
delete o[variableKey];
}
}
}
};