diff --git a/ayanova/src/api/gzform.js b/ayanova/src/api/gzform.js index c902c516..5724ea04 100644 --- a/ayanova/src/api/gzform.js +++ b/ayanova/src/api/gzform.js @@ -782,9 +782,9 @@ export default { /////////////////////////////// // On fieldValueChanged handler // formReference is an optional string name of the form ref property if alternative named form - // - Clear server errrors - // - Flag dirty - // - check and flag validity + // - Clear server errrors for this field + // - Flag form dirty + // - check and flag form validity // // fieldValueChanged(vm, ref, formReference) { @@ -808,43 +808,36 @@ export default { return; } - // console.log("gzform::fieldValueChanged, values:", { - // ref: ref, - // objValue: vm[ref], - // refValue: vm.$refs[ref].value - // }); - - //If ref appears in the formState.serverErrors details collection, remove each one - //m is a mutated array with only the remaining (not removed) elements left - //that did NOT pass the truthy test function - //might be an indexed item //this is what we're dealing with // { "code": "2200", "details": [ { "message": "LT:PurchaseOrderReceiptItemQuantityReceivedErrorInvalid", "target": "Items[0].QuantityReceived", "error": "2203" } ], "message": "ErrorAPI2200" } //let rowErrorTargetStart = `${collectionName}[${rowIndex}].`.toLowerCase(); + //# REMOVE SERVER ERRORS FOR THIS FIELD REF let targetRef = ref.toLowerCase(); - // if(targetRef.includes("].")){ - // //it's an indexed reference so change - // } - let m = []; - console.log("details", vm.formState.serverError.details); + //NOTE: This block of code is meant to remove all detailed server errors where the Target matches the current referenced control + //Then it checks to see if there is anything left in details as this might have been all there was and if so removes that whole thing + //leaving only errors for other fields or nothing if this ref field was all the errors left + + //Remove any server errors that are for our target ref field + //and also set a flag if there *are* any server errors for our target field + let targetFieldHasServerError = false; + if (vm.formState.serverError.details) { - m = vm.formState.serverError.details.filter(function(o) { - if (o.target) {//<----WTF? Shouldn't this be the opposite? - return false; + let i = vm.formState.serverError.details.length; + //iterate backwards so we can mutate the array in place + while (i--) { + var o = vm.formState.serverError.details[i]; + if (o.target && o.target.toLowerCase() == targetRef) { + //remove it, it's for our ref field + vm.formState.serverError.details.splice(i, 1); + targetFieldHasServerError = true; } - - console.log("comparing values:", { - errorTarget: o.target.toLowerCase(), - targetRef: targetRef - }); - - return o.target.toLowerCase() != targetRef; - }); + } } + //# CLEAN UP SERVER ERRORS IF NONE LEFT //If there are no more errors in details then remove the whole thing as it's no longer required if ( vm.formState.serverError.details && @@ -858,31 +851,23 @@ export default { } } - //TODO: find a cleaner way to remove old validation on the control, why can't it just be set on the control referenced?? - + //# CLEAR OUT STALE VALIDATION ERRORS FOR CONTROL //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 - console.log("about to clear old validation values are: ", { - ref: ref, - m: m - }); - if (m.length > 0) { - triggeringChange = true; + //TODO: find a cleaner way to remove old validation on the control, why can't it just be set on the control referenced?? + + if (targetFieldHasServerError) { + triggeringChange = true; let val = vm.obj[ref]; - console.log("clearning old validation values are: ", { - val: val, - ref: ref, - m: m - }); vm.obj[ref] = null; vm.obj[ref] = val; triggeringChange = false; } - //Update the form status + //# UPDATE FORM STATUS let formValid = formControl.validate(); that.setFormState({ vm: vm, diff --git a/ayanova/src/views/inv-purchase-order.vue b/ayanova/src/views/inv-purchase-order.vue index fccb0f67..610c692b 100644 --- a/ayanova/src/views/inv-purchase-order.vue +++ b/ayanova/src/views/inv-purchase-order.vue @@ -222,7 +222,7 @@ - + {{ formState.serverError }}