From 3dc39cbd3612446c8bec6206e5865fba3197e64f Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 26 Nov 2019 19:02:24 +0000 Subject: [PATCH] --- ayanova/src/api/gzform.js | 46 +++++++++++++++---- .../src/components/custom-fields-control.vue | 9 +++- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/ayanova/src/api/gzform.js b/ayanova/src/api/gzform.js index 427de087..584ab0b7 100644 --- a/ayanova/src/api/gzform.js +++ b/ayanova/src/api/gzform.js @@ -151,20 +151,15 @@ function getErrorBoxErrors(vm, errs) { } export default { - todo: make a customFieldsCheck() rule, see todo.txt top item under "now" + /////////////////////////////// // REQUIRED // - required(vm, ref, subvm) { + required(vm, ref) { if (vm.formState.loading) { return false; } - - if(subvm){ - debugger; - console.log("gzform:required() being called from custom fields control: ref=" + ref + " customFields value = " + vm.$refs.customFields.value); - - } + var ctrl = getControl(vm, ref); if (typeof ctrl == "undefined") { return false; @@ -350,6 +345,41 @@ export default { valid: false }); return err; + }, + /////////////////////////////// + // CUSTOMFIELDS + // + customFieldsCheck(vm, ref, subvm, fieldName) { + if (vm.formState.loading) { + return false; + } + + if (window.$gz.errorHandler.devMode()) { + //make sure there is a customFields control in the refs to work with + //this is to ensure naming is correct mostly + if (!window.$gz._.has(vm.$refs, "customFields")) { + throw "DEV ERROR gzform::customFieldsCheck() -> vm.$refs.customFields is missing. Is it named correctly?"; + } + } + +var ctrl= getControl(vm,"customFields"); +var cdata = getControlValue(ctrl); + +return false; +//TESTING: assume it's always a broken rule just to test if the rules will display properly + + // "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}", + var err = window.$gz.locale.get("ErrorRequiredFieldEmpty"); + //var fieldName = getControlLabel(ctrl); + err = window.$gz._.replace(err, "{0}", fieldName); + //lodash replace only replaces first instance so need to do it twice + err = window.$gz._.replace(err, "{0}", fieldName); + //Update the form status + this.setFormState({ + vm: vm, + valid: false + }); + return err; }, /////////////////////////////// // SERVER ERRORS diff --git a/ayanova/src/components/custom-fields-control.vue b/ayanova/src/components/custom-fields-control.vue index ae1a5cf4..bcdfaebf 100644 --- a/ayanova/src/components/custom-fields-control.vue +++ b/ayanova/src/components/custom-fields-control.vue @@ -53,7 +53,14 @@ :label="lt(item.fld)" :ref="item.fld" :error-messages="form().serverErrors(parentVM, item.fld)" - :rules="[form().required(parentVM, item.fld, _self)]" + :rules="[ + form().customFieldsCheck( + parentVM, + item.dataKey, + _self, + lt(item.fld) + ) + ]" auto-grow clearable >