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
This commit is contained in:
Sherfin Shamsudeen 2021-12-26 20:17:53 +05:30 committed by GitHub
parent 315760b6f8
commit 248b61dee6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);