fix issue with default option logic

This commit is contained in:
Hetu Nandu 2020-03-17 19:09:06 +05:30
parent 5cb24aa7c4
commit ea1d4cbde9

View File

@ -21,6 +21,7 @@ class DropdownWidget extends BaseWidget<DropdownWidgetProps, WidgetState> {
selectionType: VALIDATION_TYPES.TEXT,
selectedIndexArr: VALIDATION_TYPES.ARRAY,
isRequired: VALIDATION_TYPES.BOOLEAN,
defaultOptionValue: VALIDATION_TYPES.TEXT,
};
}
static getDerivedPropertiesMap() {
@ -64,18 +65,21 @@ class DropdownWidget extends BaseWidget<DropdownWidgetProps, WidgetState> {
) {
this.updateWidgetMetaProperty("selectedIndex", undefined);
this.updateWidgetMetaProperty("selectedIndexArr", []);
} else if (
(this.props.selectedIndex !== prevProps.selectedIndex &&
this.props.selectedIndex === undefined) ||
this.props.defaultOptionValue !== prevProps.defaultOptionValue
) {
const selectedIndex = _.findIndex(this.props.options, option => {
return option.value === this.props.defaultOptionValue;
});
if (selectedIndex > -1) {
this.updateWidgetMetaProperty("selectedIndex", selectedIndex);
} else {
this.updateWidgetMetaProperty("selectedIndex", undefined);
}
if (this.props.defaultOptionValue) {
if (
(this.props.selectedIndex !== prevProps.selectedIndex &&
this.props.selectedIndex === undefined) ||
this.props.defaultOptionValue !== prevProps.defaultOptionValue
) {
const selectedIndex = _.findIndex(this.props.options, option => {
return option.value === this.props.defaultOptionValue;
});
if (selectedIndex > -1) {
this.updateWidgetMetaProperty("selectedIndex", selectedIndex);
} else {
this.updateWidgetMetaProperty("selectedIndex", undefined);
}
}
}
}