From 0144432d20c11de1df353d96f962318e7e9b25ac Mon Sep 17 00:00:00 2001 From: Artem Rys Date: Thu, 8 Dec 2022 17:00:25 +0100 Subject: [PATCH] fix(CODE): ADDON-58867 Fixed cancelling selected dropdown value (#188) Co-authored-by: Tushar Balar --- ui/src/main/webapp/components/BaseFormView.jsx | 9 ++++++--- ui/src/main/webapp/components/SingleInputComponent.jsx | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ui/src/main/webapp/components/BaseFormView.jsx b/ui/src/main/webapp/components/BaseFormView.jsx index 44e7b4b1d..d959564c1 100644 --- a/ui/src/main/webapp/components/BaseFormView.jsx +++ b/ui/src/main/webapp/components/BaseFormView.jsx @@ -698,7 +698,7 @@ class BaseFormView extends PureComponent { if (required && !currentValue) { load = false; data[dependency] = null; - } else if (currentValue === 'RESET_VALUE') { + } else if (currentValue === 'RESET_DROPDOWN_VALUE') { load = true; } else { data[dependency] = currentValue; @@ -713,7 +713,10 @@ class BaseFormView extends PureComponent { } }); } - changes[field] = { value: { $set: targetValue } }; + + // This is the custom logic to handle the dropdown's reset value, and we are setting null value + const target_value = targetValue === 'RESET_DROPDOWN_VALUE' ? null : targetValue; + changes[field] = { value: { $set: target_value } }; const newFields = update(this.state, { data: changes }); const tempState = this.clearAllErrorMsg(newFields); @@ -722,7 +725,7 @@ class BaseFormView extends PureComponent { if (this.hookDeferred) { this.hookDeferred.then(() => { if (typeof this.hook.onChange === 'function') { - this.hook.onChange(field, targetValue, tempState); + this.hook.onChange(field, target_value, tempState); } }); } diff --git a/ui/src/main/webapp/components/SingleInputComponent.jsx b/ui/src/main/webapp/components/SingleInputComponent.jsx index b257996e3..0a0a02f42 100755 --- a/ui/src/main/webapp/components/SingleInputComponent.jsx +++ b/ui/src/main/webapp/components/SingleInputComponent.jsx @@ -160,7 +160,7 @@ function SingleInputComponent(props) { data-test="clear" appearance="secondary" icon={} - onClick={() => restProps.handleChange(field, 'RESET_VALUE')} + onClick={() => restProps.handleChange(field, 'RESET_DROPDOWN_VALUE')} /> ) : null}