From e07b95a71312697d9a59be3bce39b7521badce87 Mon Sep 17 00:00:00 2001 From: Stanislav Popov Date: Tue, 25 Aug 2020 16:16:57 +0500 Subject: [PATCH] fix: never validate empty cells (except zero) --- pages/index.vue | 28 +++++++++++++++------------- store/index.js | 22 ++++++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index b02fb11..5d16b69 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -210,7 +210,7 @@ export default { } else { // align left for text - if (field.type == 'string') { + if (field.type === 'string') { rules.push({ class: 'align-left', condition: () => true @@ -238,13 +238,13 @@ export default { } } - // fix validateRules: test rules - /* if (columnName == 'cron'){ + // for debug + /*if (columnName == 'status'){ validateRules = { - warning: '> 1', - error: '< 1' + error: '!= 200' }; - } */ + console.log() + }*/ // warning for (let errType of ['warning', 'error']) { @@ -254,14 +254,16 @@ export default { condition: row => { const val = row[columnName]; const func = this.getValidateFunc(validateRules[errType]); - if(columnName == 'cron') { - // console.log('errType: ', errType); - // console.log('rules: ', validateRules[errType]); - // console.log('val: ', val); - // console.log('valid: ', func(val)); - // console.log(''); - } + // for debug + /*if(columnName == 'status') { + console.log('errType: ', errType); + console.log('rules: ', validateRules[errType]); + console.log('val: ', val); + console.log('valid: ', func(val)); + console.log(''); + }*/ + return func(val); } }); diff --git a/store/index.js b/store/index.js index 824132b..8d3c9bc 100644 --- a/store/index.js +++ b/store/index.js @@ -175,17 +175,23 @@ export const getters = { let expected = res[2]; if(!['==', '==='].includes(operator)) expected = parseFloat(expected); + // always not match for empty values (except 0) + const funcReturn = (val, condition) => { + if ([null, undefined, ''].includes(val)) return false; + return condition; + } + // console.log('operator: ', operator); // console.log('expected: ', expected); const funcs = { - '==': (v) => v == expected, - '===': (v) => v === expected, - '!=': (v) => v != expected, - '!==': (v) => v !== expected, - '>': (v) => v > expected, - '>=': (v) => v >= expected, - '<': (v) => v < expected, - '<=': (v) => v <= expected, + '==': (v) => funcReturn(v, v == expected), + '===': (v) => funcReturn(v, v === expected), + '!=': (v) => funcReturn(v, v != expected), + '!==': (v) => funcReturn(v, v !== expected), + '>': (v) => funcReturn(v, v > expected), + '>=': (v) => funcReturn(v, v >= expected), + '<': (v) => funcReturn(v, v < expected), + '<=': (v) => funcReturn(v, v <= expected), }; if (funcs[operator]) return funcs[operator]; }