mirror of https://github.com/nocodb/nocodb
Pranav C
3 years ago
2 changed files with 91 additions and 21 deletions
@ -0,0 +1,31 @@
|
||||
const booleanOptions = [ |
||||
{ checked: true, unchecked: false }, |
||||
{ x: true, '': false }, |
||||
{ yes: true, no: false }, |
||||
{ y: true, n: false }, |
||||
{ 1: true, 0: false }, |
||||
{ '[x]': true, '[]': false, '[ ]': false }, |
||||
{ '☑': true, '': false }, |
||||
{ '✅': true, '': false }, |
||||
{ '✓': true, '': false }, |
||||
{ '✔': true, '': false }, |
||||
{ enabled: true, disabled: false }, |
||||
{ on: true, off: false }, |
||||
{ done: true, '': false } |
||||
] |
||||
const aggBooleanOptions = booleanOptions.reduce((obj, o) => ({ ...obj, ...o }), {}) |
||||
export const isCheckboxType = (values, col = '') => { |
||||
let options = booleanOptions |
||||
for (let i = 0; i < values.length; i++) { |
||||
let val = col ? values[i][col] : values[i] |
||||
val = val === null || val === undefined ? '' : val |
||||
options = options.filter(v => val in v) |
||||
if (!options.length) { |
||||
return false |
||||
} |
||||
} |
||||
return options |
||||
} |
||||
export const getCheckboxValue = (value) => { |
||||
return value && aggBooleanOptions[value] |
||||
} |
Loading…
Reference in new issue