From b54321b36566ecc6fa267838226ea9e91d13a843 Mon Sep 17 00:00:00 2001 From: avrilpearl Date: Thu, 11 Apr 2019 15:31:32 -0400 Subject: [PATCH 1/3] react/DP-13450--Fix-InputCurrency-OnBlurBug --- .../components/atoms/forms/InputCurrency/index.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/react/src/components/atoms/forms/InputCurrency/index.js b/react/src/components/atoms/forms/InputCurrency/index.js index 2e8d8e4d30..b99106e0ab 100644 --- a/react/src/components/atoms/forms/InputCurrency/index.js +++ b/react/src/components/atoms/forms/InputCurrency/index.js @@ -24,7 +24,7 @@ const Currency = (props) => { 'ma__input-currency__control': true, 'js-is-required': props.required }); - let errorMsg = ''; + const errorMsg = ''; const toCurrency = (number, decimal) => { if (is.number(number)) { if (props.language) { @@ -146,17 +146,14 @@ const Currency = (props) => { inputEl.setAttribute('placeholder', props.placeholder); } let newValue = isNotNumber ? '' : Number(numbro.unformat(stringValue)); - if (props.required && is.empty(stringValue)) { - errorMsg = 'Please enter a value.'; - context.updateState({ showError: true, errorMsg }); - } else if (!is.empty(stringValue)) { - if (!hasNumberProperty(props, 'max') || newValue > props.max) { + if (!is.empty(newValue)) { + if (hasNumberProperty(props, 'max') && newValue > props.max) { newValue = props.max; } - if (!hasNumberProperty(props, 'min') || newValue < props.min) { + if (hasNumberProperty(props, 'min') && newValue < props.min) { newValue = props.min; } - const updateError = displayErrorMessage(!is.empty(stringValue) ? newValue : ''); + const updateError = displayErrorMessage(newValue); context.updateState({ value: toCurrency(newValue, countDecimals(props.step)), ...updateError }, () => { if (is.fn(props.onBlur)) { props.onBlur(newValue); From d4da59160f10fbf8e07fed8f634330a07af0eb8d Mon Sep 17 00:00:00 2001 From: avrilpearl Date: Thu, 11 Apr 2019 15:34:42 -0400 Subject: [PATCH 2/3] add changelog --- changelogs/DP-13450.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/DP-13450.md diff --git a/changelogs/DP-13450.md b/changelogs/DP-13450.md new file mode 100644 index 0000000000..1ebf62f251 --- /dev/null +++ b/changelogs/DP-13450.md @@ -0,0 +1,3 @@ +Patch +Fixed +- (React) [InputCurrency] DP-13450: Fixed bug relating to error handling on blur in InputCurrency. #533 \ No newline at end of file From 0b01621542ea29ef6de10818bde457e5d56d637f Mon Sep 17 00:00:00 2001 From: Minghua Sun Date: Thu, 11 Apr 2019 16:02:45 -0400 Subject: [PATCH 3/3] Update react/src/components/atoms/forms/InputCurrency/index.js --- react/src/components/atoms/forms/InputCurrency/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/react/src/components/atoms/forms/InputCurrency/index.js b/react/src/components/atoms/forms/InputCurrency/index.js index b99106e0ab..f4c4ad383c 100644 --- a/react/src/components/atoms/forms/InputCurrency/index.js +++ b/react/src/components/atoms/forms/InputCurrency/index.js @@ -24,7 +24,6 @@ const Currency = (props) => { 'ma__input-currency__control': true, 'js-is-required': props.required }); - const errorMsg = ''; const toCurrency = (number, decimal) => { if (is.number(number)) { if (props.language) {