Skip to content

Commit

Permalink
fix: never validate empty cells (except zero)
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Aug 25, 2020
1 parent 6c5f594 commit e07b95a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
28 changes: 15 additions & 13 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']) {
Expand All @@ -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);
}
});
Expand Down
22 changes: 14 additions & 8 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit e07b95a

Please sign in to comment.