From d3406087987c434da4aa3c470a6b0150ebde1208 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 25 Mar 2019 21:58:36 +0000 Subject: [PATCH] --- ayanova/devdocs/todo.txt | 2 -- ayanova/src/api/gzvalidate.js | 40 +++++++++++++++++++++ ayanova/src/api/locale.js | 3 +- ayanova/src/views/inventory-widget-edit.vue | 4 +-- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index dfe3d6cd..02e94811 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -14,8 +14,6 @@ TODO CLIENT STUFF TODO NEXT -Being screamed at so shutting down for today :( - GZ VALIDATE - Add rule isNumeric diff --git a/ayanova/src/api/gzvalidate.js b/ayanova/src/api/gzvalidate.js index 6272ac59..c22836f3 100644 --- a/ayanova/src/api/gzvalidate.js +++ b/ayanova/src/api/gzvalidate.js @@ -18,6 +18,20 @@ function isEmpty(o) { return !o; } +//////////////////////////////////// +// isInt value?? +// +//FROM HERE: https://stackoverflow.com/a/14794066/8939 +//fast test if is an integer: +function isInt(value) { + var x; + if (isNaN(value)) { + return false; + } + x = parseFloat(value); + return (x | 0) === x; +} + //////////////////////////////////// // Get control from ref // @@ -146,5 +160,31 @@ export default { } else { return false; } + }, + /////////////////////////////// + // INTEGER + // + Integer(v, ref) { + + var ctrl = getControl(v, ref); + if(typeof ctrl == 'undefined'){ + return false; + } + + var value = getControlValue(ctrl); + if (isEmpty(value)) { + return false; + } + + if(isInt(value)){ + return false; + } + + + + // "ErrorFieldValueNotInteger": "Value must be an integer" + var err = locale.get("ErrorFieldValueNotInteger"); + + return err; } }; diff --git a/ayanova/src/api/locale.js b/ayanova/src/api/locale.js index 4eba5a98..38d62bbf 100644 --- a/ayanova/src/api/locale.js +++ b/ayanova/src/api/locale.js @@ -67,7 +67,8 @@ export default { "RecordHistory", "ErrorFieldLengthExceeded", "ErrorStartDateAfterEndDate", - "ErrorRequiredFieldEmpty" + "ErrorRequiredFieldEmpty", + "ErrorFieldValueNotInteger" ], decimalValidate(required) { return { required: required, decimal: [2, this.formats.decimalSeparator] }; diff --git a/ayanova/src/views/inventory-widget-edit.vue b/ayanova/src/views/inventory-widget-edit.vue index 1ea58357..91b22f2f 100644 --- a/ayanova/src/views/inventory-widget-edit.vue +++ b/ayanova/src/views/inventory-widget-edit.vue @@ -26,8 +26,8 @@ v-model="obj.count" :counter="10" :label="this.$gzlocale.get('WidgetCount')" - ref="count" - :rules="[this.$gzv.Required(this,'count')]" + ref="count" + :rules="[this.$gzv.Integer(this,'count'),this.$gzv.Required(this,'count')]" required >