Merge branch 'fix/update-loop-form-input' into 'release'

Fix another issue with dropdown default value

See merge request theappsmith/internal-tools-client!388
This commit is contained in:
Hetu Nandu 2020-03-17 14:12:44 +00:00
commit d42d40dd6d

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