From 248b61dee6db8b26170c47b3e27f0bd343ff50e2 Mon Sep 17 00:00:00 2001 From: Sherfin Shamsudeen Date: Sun, 26 Dec 2021 20:17:53 +0530 Subject: [PATCH] Set dropdown value to invalid if value is not present in available values (#1641) * Set dropdown value to invalid if value is not present in available values * Reset to default value if existing value is not selectable --- frontend/src/Editor/Components/DropDown.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/src/Editor/Components/DropDown.jsx b/frontend/src/Editor/Components/DropDown.jsx index ece706326b..2859e8275d 100644 --- a/frontend/src/Editor/Components/DropDown.jsx +++ b/frontend/src/Editor/Components/DropDown.jsx @@ -27,14 +27,18 @@ export const DropDown = function DropDown({ height, validate, properties, styles }, [isValid]); useEffect(() => { - setCurrentValue(value); - setExposedVariable('value', value); + let newValue = undefined; + if (values?.includes(value)) newValue = value; + + setCurrentValue(newValue); + setExposedVariable('value', newValue); // eslint-disable-next-line react-hooks/exhaustive-deps }, [value]); useEffect(() => { let newValue = undefined; - if (values?.includes(value)) newValue = value; + if (values?.includes(currentValue)) newValue = currentValue; + else if (values?.includes(value)) newValue = value; setCurrentValue(newValue); setExposedVariable('value', newValue);