From d41dd49c3b52b1afd62f879389bd69c06bbe96d7 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 22 Mar 2019 19:54:11 +0000 Subject: [PATCH] --- ayanova/src/api/gzvalidate.js | 146 +++++++++++++------- ayanova/src/views/inventory-widget-edit.vue | 4 +- 2 files changed, 99 insertions(+), 51 deletions(-) diff --git a/ayanova/src/api/gzvalidate.js b/ayanova/src/api/gzvalidate.js index 0a90d56e..c54b989b 100644 --- a/ayanova/src/api/gzvalidate.js +++ b/ayanova/src/api/gzvalidate.js @@ -1,4 +1,4 @@ -/* eslint-disable */ +/* Xeslint-disable */ /////////////////////////////// // GZVALIDATE // @@ -9,6 +9,7 @@ import dayjs from "dayjs"; import locale from "./locale"; import _ from "../libs/lodash.min.js"; +import errorHandler from "./errorhandler"; function isEmpty(o) { if (typeof o == "number" && o == 0) { @@ -20,10 +21,16 @@ function isEmpty(o) { //////////////////////////////////// // Get control from ref // -function getControl(ref) { +function getControl(v, ref) { var ctrl = v.$refs[ref]; - if (isEmpty(ctrl)) { - return null; + if (errorHandler.developmentModeShowErrorsImmediately) { + if (isEmpty(ctrl)) { + throw "GZValidate:getControl - the control has no label " + ctrl; + } + } else { + if (isEmpty(ctrl)) { + return null; + } } } @@ -31,6 +38,11 @@ function getControl(ref) { // Get value from control // function getControlValue(ctrl) { + /* + ctrl.$refs[ref].value 0 + ctrl.$refs[ref].label "Count" + ctrl.$refs[ref].initialValue + */ var value = ctrl.value; return value; } @@ -38,35 +50,21 @@ function getControlValue(ctrl) { //////////////////////////////////// // Get field name from control // -function getControlFieldName(ctrl) { +function getControlLabel(ctrl) { + if (errorHandler.developmentModeShowErrorsImmediately) { + if (!ctrl.label) { + throw "GZValidate:getControlLabel - the control has no label " + ctrl; + } + } return ctrl.label; } export default { - /* - ctrl.$refs[ref].value -0 -ctrl.$refs[ref].label -"Count" -ctrl.$refs[ref].initialValue - */ /////////////////////////////// // REQUIRED - // Required(ltkey, value) { - // if (!_.isEmpty(value)) { - // return false; - // } - // //get the localized rule text - // // "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}", - // var err = locale.get("ErrorRequiredFieldEmpty"); - // var fieldName = locale.get(ltkey); - // err = _.replace(err, "{0}", fieldName); - // //lodash replace only replaces first instance so need to do it twice - // err = _.replace(err, "{0}", fieldName); - // return err; - // }, + // Required(v, ref) { - var ctrl = getControl(ref); + var ctrl = getControl(v, ref); if (!ctrl) { return false; } @@ -75,10 +73,10 @@ ctrl.$refs[ref].initialValue if (!isEmpty(value)) { return false; } - //get the localized rule text + // "ErrorRequiredFieldEmpty": "{0} is a required field. Please enter a value for {0}", var err = locale.get("ErrorRequiredFieldEmpty"); - var fieldName = ctrl.label; + var fieldName = getControlLabel(ctrl); err = _.replace(err, "{0}", fieldName); //lodash replace only replaces first instance so need to do it twice err = _.replace(err, "{0}", fieldName); @@ -86,8 +84,18 @@ ctrl.$refs[ref].initialValue }, /////////////////////////////// // MAXLENGTH - //MaxLength(ltkey, value, max) { - MaxLength(v, ref) { + // + MaxLength(v, ref, max) { + var ctrl = getControl(v, ref); + if (!ctrl) { + return false; + } + + var value = getControlValue(ctrl); + if (!isEmpty(value)) { + return false; + } + if (_.isEmpty(value)) { return false; } @@ -96,7 +104,7 @@ ctrl.$refs[ref].initialValue //get the localized rule text // "ErrorFieldLengthExceeded": "{0} can not exceed {1} characters.", var err = locale.get("ErrorFieldLengthExceeded"); - var fieldName = locale.get(ltkey); + var fieldName = getControlLabel(ctrl); err = _.replace(err, "{0}", fieldName); err = _.replace(err, "{1}", max); return err; @@ -106,40 +114,80 @@ ctrl.$refs[ref].initialValue }, /////////////////////////////// // MAX 255 - Max255(ltkey, value) { - return this.MaxLength(ltkey, value, 255); + // + Max255(v, ref) { + return this.MaxLength(v, ref, 255); }, + // /////////////////////////////// + // // AFTER + // After(startDate, endDate) { + // if (_.isEmpty(startDate)) { + // return false; + // } + // if (_.isEmpty(endDate)) { + // return false; + // } + + // startDate = dayjs(startDate); + // endDate = dayjs(endDate); + + // // if either is not valid. + // if (!startDate || !endDate) { + // return false; + // } + + // if (startDate.isAfter(endDate)) { + // // "ErrorStartDateAfterEndDate": "Start date must be earlier than stop / end date", + // var err = locale.get("ErrorStartDateAfterEndDate"); + // return err; + // } else { + // return false; + // } + // }, /////////////////////////////// // AFTER - After(startDate, endDate) { - if (_.isEmpty(startDate)) { - return false; - } - if (_.isEmpty(endDate)) { + After(v, refStart, refEnd) { + var ctrlStart = getControl(v, refStart); + if (!ctrlStart) { return false; } - startDate = dayjs(startDate); - endDate = dayjs(endDate); + var ctrlEnd = getControl(v, refEnd); + if (!ctrlEnd) { + return false; + } + + var valueStart = getControlValue(ctrlStart); + if (!isEmpty(valueStart)) { + return false; + } + + var valueEnd = getControlValue(ctrlEnd); + if (!isEmpty(valueEnd)) { + return false; + } + + if (_.isEmpty(valueStart)) { + return false; + } + if (_.isEmpty(valueEnd)) { + return false; + } + + valueStart = dayjs(valueStart); + valueEnd = dayjs(valueEnd); // if either is not valid. - if (!startDate || !endDate) { + if (!valueStart || !valueEnd) { return false; } - if (startDate.isAfter(endDate)) { + if (valueStart.isAfter(valueEnd)) { // "ErrorStartDateAfterEndDate": "Start date must be earlier than stop / end date", var err = locale.get("ErrorStartDateAfterEndDate"); return err; } else { return false; } - }, - /////////////////////////////// - // TEST - Test(ctrl, ref) { - var v = ctrl; - return false; - // return this.MaxLength(ltkey, value, 255); } }; diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index 84edb8ec..2cc47758 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -8,7 +8,7 @@ v-model="obj.name" :counter="255" :label="this.$gzlocale.get('WidgetName')" - :rules="[this.$gzv.Max255('WidgetName',obj.name)]" + :rules="[this.$gzv.Max255(this,'WidgetName')]" ref="name" > @@ -17,7 +17,7 @@ v-model="obj.serial" :counter="10" :label="this.$gzlocale.get('WidgetSerial')" - :rules="[this.$gzv.MaxLength('WidgetSerial',obj.serial,10)]" + :rules="[this.$gzv.MaxLength(this,'WidgetSerial',10)]" ref="serial" >