This commit is contained in:
2019-04-23 00:03:36 +00:00
parent 26d8ffa7de
commit 98ed94e0b8
2 changed files with 57 additions and 17 deletions

View File

@@ -124,6 +124,9 @@ export default {
// REQUIRED // REQUIRED
// //
required(vm, ref) { required(vm, ref) {
if (vm.formLoading) {
return false;
}
var ctrl = getControl(vm, ref); var ctrl = getControl(vm, ref);
if (typeof ctrl == "undefined") { if (typeof ctrl == "undefined") {
return false; return false;
@@ -140,12 +143,16 @@ export default {
err = vm.$_.replace(err, "{0}", fieldName); err = vm.$_.replace(err, "{0}", fieldName);
//lodash replace only replaces first instance so need to do it twice //lodash replace only replaces first instance so need to do it twice
err = vm.$_.replace(err, "{0}", fieldName); err = vm.$_.replace(err, "{0}", fieldName);
vm.formValid = false;
return err; return err;
}, },
/////////////////////////////// ///////////////////////////////
// MAXLENGTH // MAXLENGTH
// //
maxLength(vm, ref, max) { maxLength(vm, ref, max) {
if (vm.formLoading) {
return false;
}
var ctrl = getControl(vm, ref); var ctrl = getControl(vm, ref);
if (typeof ctrl == "undefined") { if (typeof ctrl == "undefined") {
return false; return false;
@@ -163,6 +170,7 @@ export default {
var fieldName = getControlLabel(ctrl); var fieldName = getControlLabel(ctrl);
err = vm.$_.replace(err, "{0}", fieldName); err = vm.$_.replace(err, "{0}", fieldName);
err = vm.$_.replace(err, "{1}", max); err = vm.$_.replace(err, "{1}", max);
vm.formValid = false;
return err; return err;
} else { } else {
return false; return false;
@@ -172,6 +180,9 @@ export default {
// MAX 255 // MAX 255
// //
max255(vm, ref) { max255(vm, ref) {
if (vm.formLoading) {
return false;
}
return this.maxLength(vm, ref, 255); return this.maxLength(vm, ref, 255);
}, },
/////////////////////////////// ///////////////////////////////
@@ -179,6 +190,9 @@ export default {
// (start date must precede end date) // (start date must precede end date)
// //
datePrecedence(vm, refStart, refEnd) { datePrecedence(vm, refStart, refEnd) {
if (vm.formLoading) {
return false;
}
var ctrlStart = getControl(vm, refStart); var ctrlStart = getControl(vm, refStart);
if (typeof ctrlStart == "undefined") { if (typeof ctrlStart == "undefined") {
return false; return false;
@@ -210,6 +224,7 @@ export default {
if (valueStart.isAfter(valueEnd)) { if (valueStart.isAfter(valueEnd)) {
// "ErrorStartDateAfterEndDate": "Start date must be earlier than stop / end date", // "ErrorStartDateAfterEndDate": "Start date must be earlier than stop / end date",
var err = vm.$gzlocale.get("ErrorStartDateAfterEndDate"); var err = vm.$gzlocale.get("ErrorStartDateAfterEndDate");
vm.formValid = false;
return err; return err;
} else { } else {
return false; return false;
@@ -219,6 +234,9 @@ export default {
// INTEGER IS VALID // INTEGER IS VALID
// //
integerValid(vm, ref) { integerValid(vm, ref) {
if (vm.formLoading) {
return false;
}
var ctrl = getControl(vm, ref); var ctrl = getControl(vm, ref);
if (typeof ctrl == "undefined") { if (typeof ctrl == "undefined") {
return false; return false;
@@ -238,7 +256,7 @@ export default {
// "ErrorFieldValueNotInteger": "Value must be an integer" // "ErrorFieldValueNotInteger": "Value must be an integer"
var err = vm.$gzlocale.get("ErrorFieldValueNotInteger"); var err = vm.$gzlocale.get("ErrorFieldValueNotInteger");
vm.formValid = false;
return err; return err;
}, },
/////////////////////////////// ///////////////////////////////
@@ -246,6 +264,9 @@ export default {
// Basically anything that can be a number is valid // Basically anything that can be a number is valid
// //
decimalValid(vm, ref) { decimalValid(vm, ref) {
if (vm.formLoading) {
return false;
}
//TODO: Handle commas and spaces in numbers //TODO: Handle commas and spaces in numbers
//as per vm.$gzlocale rules for numbers //as per vm.$gzlocale rules for numbers
@@ -268,7 +289,7 @@ export default {
// "ErrorFieldValueNotDecimal": "Value must be a number" // "ErrorFieldValueNotDecimal": "Value must be a number"
var err = vm.$gzlocale.get("ErrorFieldValueNotDecimal"); var err = vm.$gzlocale.get("ErrorFieldValueNotDecimal");
vm.formValid = false;
return err; return err;
}, },
/////////////////////////////// ///////////////////////////////
@@ -317,6 +338,7 @@ export default {
if (vm.serverError.message) { if (vm.serverError.message) {
err = err + "\r\n" + vm.serverError.message; err = err + "\r\n" + vm.serverError.message;
} }
vm.formValid = false;
ret.push(err); ret.push(err);
} }
//DETAIL ERRORS //DETAIL ERRORS
@@ -341,7 +363,7 @@ export default {
} }
ret.push(fldErr); ret.push(fldErr);
}); });
vm.formValid = false;
return ret; return ret;
} }
} }
@@ -378,7 +400,7 @@ export default {
// This is required so that server errors can be cleared when input is changed // This is required so that server errors can be cleared when input is changed
// //
onChange(vm, ref) { onChange(vm, ref) {
if (triggeringChange) { if (triggeringChange || vm.formLoading) {
return; return;
} }
//If ref appears in the servererrors details collection, remove each one //If ref appears in the servererrors details collection, remove each one
@@ -409,6 +431,6 @@ export default {
triggeringChange = false; triggeringChange = false;
} }
vm.formDirty = true; vm.formDirty = true;
vm.formValid = vm.$refs.form.validate(); //vm.formValid = vm.$refs.form.validate();
} }
}; };

View File

@@ -98,7 +98,7 @@
ref="active" ref="active"
:error-messages="this.$gzv.serverErrors(this,'active')" :error-messages="this.$gzv.serverErrors(this,'active')"
required required
@change="onChange('active')" @change="onChange('active')"
></v-checkbox> ></v-checkbox>
</v-flex> </v-flex>
<v-flex xs12 sm6 lg4 xl3 px-2> <v-flex xs12 sm6 lg4 xl3 px-2>
@@ -119,6 +119,8 @@
<v-flex xs6 sm4> <v-flex xs6 sm4>
READY: {{formReady}} READY: {{formReady}}
<br> <br>
LOADING: {{formLoading}}
<br>
DIRTY: {{formDirty}} DIRTY: {{formDirty}}
<br> <br>
VALID: {{formValid}} VALID: {{formValid}}
@@ -254,24 +256,27 @@ export default {
formReady: false, formReady: false,
formDirty: false, formDirty: false,
formValid: true, formValid: true,
formReadOnly: false formReadOnly: false,
formLoading: true
}; };
}, },
// watch: { watch: {
// obj: { formValid: {
// handler: function(newObj, oldObj) { handler: function(newObj, oldObj) {
// console.log("WATCH OBJ CHANGED "); console.log("Valid CHANGED, was " + oldObj + " Now is " + newObj);
// }, }
// deep: true }
// } },
// },
methods: { methods: {
onChange(ref) { onChange(ref) {
console.log("onChange:" + ref); if (!this.formLoading) {
this.$gzv.onChange(this, ref); console.log("onChange:" + ref);
this.$gzv.onChange(this, ref);
}
}, },
getDataFromApi() { getDataFromApi() {
this.formLoading = true;
var url = "Widget/" + this.$route.params.id; var url = "Widget/" + this.$route.params.id;
var vm = this; var vm = this;
this.$gzv.deleteAllErrorBoxErrors(this); this.$gzv.deleteAllErrorBoxErrors(this);
@@ -283,15 +288,26 @@ export default {
vm.$gzv.setErrorBoxErrors(vm); vm.$gzv.setErrorBoxErrors(vm);
} else { } else {
vm.obj = res.data; vm.obj = res.data;
//WTF? Can't seem to set this to valid after the data has loaded, it seems to validate outside of here
//tried to set nexttick as latest attempt, but it's not working
//tried to defer validation until form is loaded but that's also not working for some reason
//wtf is going on here???
vm.nextTick(function() {
vm.formValid = true;
vm.formDirty = false;
});
} }
this.formLoading = false;
}) })
.catch(function handleGetDataFromAPIError(error) { .catch(function handleGetDataFromAPIError(error) {
vm.formLoading = false;
vm.$gzHandleFormError(error, vm); vm.$gzHandleFormError(error, vm);
}); });
}, },
submit() { submit() {
//check if form is valid, as far as I know this is the way you're supposed to do it and in testing it does not force all fields to revalidate individually //check if form is valid, as far as I know this is the way you're supposed to do it and in testing it does not force all fields to revalidate individually
if (this.$refs.form.validate()) { if (this.$refs.form.validate()) {
this.formLoading = true;
var vm = this; var vm = this;
var url = "Widget/" + this.$route.params.id; var url = "Widget/" + this.$route.params.id;
@@ -301,6 +317,7 @@ export default {
this.$gzapi this.$gzapi
.upsert(url, this.obj) .upsert(url, this.obj)
.then(res => { .then(res => {
this.formLoading = false;
if (res.error) { if (res.error) {
vm.serverError = res.error; vm.serverError = res.error;
vm.$gzv.setErrorBoxErrors(vm); vm.$gzv.setErrorBoxErrors(vm);
@@ -319,6 +336,7 @@ export default {
} }
}) })
.catch(function handleSubmitError(error) { .catch(function handleSubmitError(error) {
vm.formLoading = false;
vm.$gzHandleFormError(error, vm); vm.$gzHandleFormError(error, vm);
}); });
} }