Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 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,16 @@ class MoneyRequestAmountPage extends React.Component {
* @returns {Object}
*/
getNewState(prevState, newAmount) {
if (!this.validateAmount(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);
Comment thread
akinwale marked this conversation as resolved.
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 +198,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