Skip to content

TextField/textChange - trying to do input formatting when text changes #10249

Closed

Description

@sudiptosen

Issue Description

I have been trying to auto format TextField entry for phone# as 212-222-3333. So as the user types 212 it will add 212-and so on. But on iOS assigning the formatted text on textChange event, repeats the last entry.

So I created this Preview. The preview app tries to add a "-" after every input (just to simplify the concept) . So if we add "2" it should make it "2-". But instead in iOS the TextField makes it "2-2".

I have submitted this on the Discord/Help channel as well.

Please help. Appreciate it.

Reproduction

Here is the Preview app is here:

Preview Link

Relevant log output (if applicable)

No response

Environment

OS: macOS 13.2.1
CPU: (10) arm64 Apple M1 Max
Shell: /bin/zsh
node: 18.14.1
npm: 9.3.1
nativescript: 8.4.0

# android
java: 18.0.1
ndk: Not Found
apis: Not Found
build_tools: Not Found
system_images: Not Found

# ios
xcode: 14.2/14C18
cocoapods: 1.11.3
python: 2.7.18
python3: 3.10.7
ruby: 2.7.6
platforms: 
  - DriverKit 22.2
  - iOS 16.2
  - macOS 13.1
  - tvOS 16.1
  - watchOS 9.1

Dependencies

"dependencies": {
  "@angular/animations": "~15.1.0",
  "@angular/common": "~15.1.0",
  "@angular/compiler": "~15.1.0",
  "@angular/core": "~15.1.0",
  "@angular/forms": "~15.1.0",
  "@angular/platform-browser": "~15.1.0",
  "@angular/platform-browser-dynamic": "~15.1.0",
  "@angular/router": "~15.1.0",
  "@nativescript/angular": "^15.0.0",
  "@nativescript/core": "~8.4.0",
  "@nativescript/theme": "~3.0.2",
  "rxjs": "~7.6.0",
  "zone.js": "~0.12.0"
},
"devDependencies": {
  "@angular-devkit/build-angular": "~15.1.0",
  "@angular/compiler-cli": "~15.1.0",
  "@nativescript/ios": "8.4.1",
  "@nativescript/preview-cli": "1.0.2",
  "@nativescript/types": "~8.4.0",
  "@nativescript/webpack": "~5.0.12",
  "@ngtools/webpack": "~15.1.0",
  "typescript": "~4.8.4"
}

Please accept these terms

Activity

  1. dammynex commented on Apr 5, 2023

    @dammynex

    There's an issue with TextField on iOS it keeps truncating the last character input.

    Screen.Recording.2023-04-05.at.4.03.43.AM.mov
  2. Nawalsubject commented on Apr 7, 2023

    @Nawalsubject

    same problem here, very blocking

  3. self-assigned this
    on Apr 7, 2023
  4. NathanWalker commented on Apr 7, 2023

    @NathanWalker
    Contributor

    Thank you for reporting @sudiptosen and confirming @Nawalsubject - we're looking at posting a 8.5.1 update and will see about including anything needed here.

  5. NathanWalker commented on Apr 7, 2023

    @NathanWalker
    Contributor

    @sudiptosen @Nawalsubject this appears fixed on 8.5 already, see attached video. I noticed the package you shared is using 8.4 - After updating, if further issue, please post back with updated package.json and perhaps simulator details. This is from a iOS 16.2, iPhone 14 Pro...

    ns-8-5-textfield.mov
  6. NathanWalker commented on Apr 8, 2023

    @NathanWalker
    Contributor

    @sudiptosen @Nawalsubject After looking at your linked stackblitz, I was able to tell you were trying to do input formatting with textChange which is possible but fairly tricky to get conditions right. The issue as reported wasn't related to a core issue but I ended up implementing a feature to make this easier for these cases which you can now find in this StackBlitz which is based off of yours:
    https://stackblitz.com/edit/nativescript-textfield-value-formatter?file=src%2Fapp%2Fitem%2Fitems.component.html

    It uses 8.5.1-rc.3 which includes the new valueFormatter feature to make your case simpler. Core patch likely to be released this upcoming week.

  7. changed the title [-]TextField/textChange - Repeats last character (iOS only Issue)[/-] [+]TextField/textChange - trying to do input formatting when text changes[/+] on Apr 8, 2023
  8. Salvetori commented on Apr 8, 2023

    @Salvetori

    the issue persists on iOS 16.4— specifically textChange is called twice on input, and the first backspace in a TextField ignores the event

  9. deleted a comment from OPADA-Eng on Apr 9, 2023
  10. locked as resolved and limited conversation to collaborators on Apr 9, 2023
  11. NathanWalker commented on Apr 13, 2023

    @NathanWalker
    Contributor

    @Salvetori @sudiptosen @Nawalsubject I'm going to create a separate issue isolating just iOS 16.4 on this cause the original case involved formatting on textChange which the above addresses but the key detail is iOS 16.4 specifically behaves differently than 16.2: #10267
    Thank you @Salvetori for clarifying this.

  12. NathanWalker commented on Apr 14, 2023

    @NathanWalker
    Contributor

    Confirmed iOS 16.4 is actually ok too - see #10267 - can post anything further on that issue if you all find otherwise.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions