From 67588f72151f2f8364b1bc3198c533d4ae3b6231 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Mon, 17 Apr 2023 18:37:10 +0100 Subject: [PATCH 1/2] implement stripSpacesFromAmount method to remove spaces from pasted values --- src/pages/iou/steps/MoneyRequestAmountPage.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestAmountPage.js b/src/pages/iou/steps/MoneyRequestAmountPage.js index 10c260895490..912da7f18939 100755 --- a/src/pages/iou/steps/MoneyRequestAmountPage.js +++ b/src/pages/iou/steps/MoneyRequestAmountPage.js @@ -59,6 +59,7 @@ class MoneyRequestAmountPage extends React.Component { this.updateLongPressHandlerState = this.updateLongPressHandlerState.bind(this); this.updateAmount = this.updateAmount.bind(this); this.stripCommaFromAmount = this.stripCommaFromAmount.bind(this); + this.stripSpacesFromAmount = this.stripSpacesFromAmount.bind(this); this.focusTextInput = this.focusTextInput.bind(this); this.navigateToCurrencySelectionPage = this.navigateToCurrencySelectionPage.bind(this); this.amountViewID = 'amountView'; @@ -126,13 +127,14 @@ class MoneyRequestAmountPage extends React.Component { * @returns {Object} */ getNewState(prevState, newAmount) { - if (!this.validateAmount(newAmount)) { + const newAmountWithoutSpaces = this.stripSpacesFromAmount(newAmount); + if (!this.validateAmount(newAmountWithoutSpaces)) { // Use a shallow copy of selection to trigger setSelection // More info: https://github.com/Expensify/App/issues/16385 return {amount: prevState.amount, selection: {...prevState.selection}}; } - const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmount.length); - return {amount: this.stripCommaFromAmount(newAmount), selection}; + const selection = this.getNewSelection(prevState.selection, prevState.amount.length, newAmountWithoutSpaces.length); + return {amount: this.stripCommaFromAmount(newAmountWithoutSpaces), selection}; } /** @@ -194,6 +196,16 @@ class MoneyRequestAmountPage extends React.Component { return amount.replace(/,/g, ''); } + /** + * Strip spaces from the amount + * + * @param {String} amount + * @returns {String} + */ + stripSpacesFromAmount(amount) { + return amount.replace(/\s+/g, ''); + } + /** * Adds a leading zero to the amount if user entered just the decimal separator * From bea7af00a6a04786e612293508679300b4ae1d34 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Tue, 18 Apr 2023 18:16:23 +0100 Subject: [PATCH 2/2] add some comments --- src/pages/iou/steps/MoneyRequestAmountPage.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages/iou/steps/MoneyRequestAmountPage.js b/src/pages/iou/steps/MoneyRequestAmountPage.js index 912da7f18939..7fb169fa3d84 100755 --- a/src/pages/iou/steps/MoneyRequestAmountPage.js +++ b/src/pages/iou/steps/MoneyRequestAmountPage.js @@ -127,6 +127,8 @@ class MoneyRequestAmountPage extends React.Component { * @returns {Object} */ getNewState(prevState, newAmount) { + // Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value + // More info: https://github.com/Expensify/App/issues/16974 const newAmountWithoutSpaces = this.stripSpacesFromAmount(newAmount); if (!this.validateAmount(newAmountWithoutSpaces)) { // Use a shallow copy of selection to trigger setSelection