Skip to content

Commit

Permalink
implement stripSpacesFromAmount method to remove spaces from pasted v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
akinwale committed Apr 17, 2023
1 parent c792447 commit 67588f7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/pages/iou/steps/MoneyRequestAmountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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};
}

/**
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 67588f7

Please sign in to comment.