Skip to content

Added maxLength to IOU Amount field#5192

Merged
marcaaron merged 4 commits into
Expensify:mainfrom
akshayasalvi:iou-amt-maxlength
Sep 13, 2021
Merged

Added maxLength to IOU Amount field#5192
marcaaron merged 4 commits into
Expensify:mainfrom
akshayasalvi:iou-amt-maxlength

Conversation

@akshayasalvi

@akshayasalvi akshayasalvi commented Sep 10, 2021

Copy link
Copy Markdown
Contributor

@deetergp Can you please review?

Details

  • Added maxLength to amount field to avoid design issues

Fixed Issues

$ #5115

Tests

  1. Tested the long numbers with web typing
  2. Tested the long numbers with the number pad in mobile devices
  3. Tested the numbers with decimal point

QA Steps

Web/Desktop

  1. Go to any transaction option - Split Money or Request Money
  2. Go to the amount field and try to type a very long number - say 14+ digits.
  3. It shouldn't allow you to type more than 14 digits including the decimal point

Mobile Web/iOS/Android

  1. Go to any transaction option - Split Money or Request Money
  2. Go to the number pad and try to type a very long number - say 14+ digits.
  3. It shouldn't allow you to enter more than 14 digits including the decimal point

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

web-max-length-amount.mov

Mobile Web

mweb-max-length-amount.mov

Desktop

desktop-max-length-amount.mov

iOS

ios-max-length-amount.mov

Android

android-max-length-amount.mov

@akshayasalvi akshayasalvi requested a review from a team as a code owner September 10, 2021 16:55
@MelvinBot MelvinBot requested review from marcaaron and removed request for a team September 10, 2021 16:55
…maxlength

# Conflicts:
#	src/pages/iou/steps/IOUAmountPage.js
@marcaaron marcaaron requested a review from deetergp September 10, 2021 18:31
Comment thread src/pages/iou/steps/IOUAmountPage.js Outdated
ref={el => this.textInput = el}
value={this.state.amount}
placeholder="0"
maxLength={CONST.IOU.AMOUNT_MAX_LENGTH}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we passing this as a prop to TextInputAutoWidth? It doesn't seem like we will allow the setting a value that is larger anyway?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I added the prop first and then the number pad change. Will remove.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcaaron I checked again there are two functions updateAmount and updateAmountNumberPad.

We can do one of the three things:

  1. Retain my maxLength change
  2. Add the length change in updateAmount also
  3. Add the length change in updateAmount and call it inside updateAmountNumberPad instead of setting the state.

Please let me know which one suits better?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've kept 1. and updated the PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would lean towards including it in the validateAmount() method (which both of these methods you mentioned use) and prevent setting state instead of using the maxLength on the TextInput. It's a controlled component so if we prevent setting state the value should not change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that worked. PR updated.

Comment thread src/pages/iou/steps/IOUAmountPage.js Outdated
const amount = `${prevState.amount}${key}`;
return this.validateAmount(amount) ? {amount: this.stripCommaFromAmount(amount)} : prevState;
});
if (this.state.amount.length < CONST.IOU.AMOUNT_MAX_LENGTH) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use an early return please.

if (this.state.amount.length === CONST.IOU.AMOUNT_MAX_LENGTH) {
    return;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay will update

Comment thread src/pages/iou/steps/IOUAmountPage.js Outdated
const amount = `${prevState.amount}${key}`;
return this.validateAmount(amount) ? {amount: this.stripCommaFromAmount(amount)} : prevState;
});
if (this.state.amount.length < CONST.IOU.AMOUNT_MAX_LENGTH) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this make the effective max length 13?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the current length is < 14 then allow updating the state, else skip it. I tested this. But wouldn't matter as based on @marcaaron's comment I'll be updating the condition and the early return.

@akshayasalvi

Copy link
Copy Markdown
Contributor Author

PR updated

@marcaaron marcaaron merged commit 3e11093 into Expensify:main Sep 13, 2021
@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by @marcaaron in version: 1.0.97-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@isagoico

Copy link
Copy Markdown

This issue is failing this PR #5241

@akshayasalvi

akshayasalvi commented Sep 14, 2021

Copy link
Copy Markdown
Contributor Author

@deetergp @marcaaron It seems the maxLength=14 will not work for 3 letter currency symbols. Can you confirm if we're going to support this? Then I'll have to update the approach or are we okay to reduce maxLength to 12.

@akshayasalvi

Copy link
Copy Markdown
Contributor Author

Length 12 also caused the issue so I've made it 11 and raised a PR. Reverting the pull will still have alignment issues.

Length 12:
image

Length 11
image

@botify

botify commented Sep 15, 2021

Copy link
Copy Markdown

This has been deployed to production and is now subject to a 7-day regression period.
If no regressions arise, payment will be issued on 2021-09-22. 🎊

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by @francoisl in version: 1.0.98-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants