From ea1d4cbde9e5ac08135068edf90ff8dc98f4eecf Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Tue, 17 Mar 2020 19:09:06 +0530 Subject: [PATCH] fix issue with default option logic --- app/client/src/widgets/DropdownWidget.tsx | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/client/src/widgets/DropdownWidget.tsx b/app/client/src/widgets/DropdownWidget.tsx index 71221e3d20..88b87441ee 100644 --- a/app/client/src/widgets/DropdownWidget.tsx +++ b/app/client/src/widgets/DropdownWidget.tsx @@ -21,6 +21,7 @@ class DropdownWidget extends BaseWidget { 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 { ) { 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); + } } } }