diff --git a/src/components/conditional.js b/src/components/conditional.js index 526feac5f..0bd89e9b1 100644 --- a/src/components/conditional.js +++ b/src/components/conditional.js @@ -34,6 +34,13 @@ const [visible, setVisible] = useState(); const logic = useLogic(displayLogic); + function isEmpty(value) { + return ( + value == null || + (typeof value === 'string' && value.trim().length === 0) + ); + } + const evalCondition = () => { if (!initVisibility && leftValue === '' && rightValue === '') { return false; @@ -59,6 +66,12 @@ return leftParsed >= rightParsed; case 'lteq': return leftParsed <= rightParsed; + case 'in': { + if (isEmpty(leftParsed) || isEmpty(rightParsed)) return false; + const leftArr = leftParsed.split(',') || leftParsed; + const rightArr = rightParsed.split(',') || rightParsed; + return leftArr.some((i) => rightArr.includes(i)); + } default: return leftParsed === rightParsed; } diff --git a/src/prefabs/structures/Conditional/options/index.ts b/src/prefabs/structures/Conditional/options/index.ts index b38161261..8895e6fa1 100644 --- a/src/prefabs/structures/Conditional/options/index.ts +++ b/src/prefabs/structures/Conditional/options/index.ts @@ -82,6 +82,10 @@ export const conditionalOptions = { name: 'Less than or equal to', value: 'lteq', }, + { + name: 'IN', + value: 'in', + }, ], condition: showIf('type', 'EQ', 'singleRule'), },