Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Entry's MaskedBehavior causes the cursor to go to the end of an Entry when user's changing something in the middle of it #1879

Open
sjasionowska opened this issue Jun 29, 2022 · 8 comments
Labels
bug Something isn't working. Breaky break.

Comments

@sjasionowska
Copy link

sjasionowska commented Jun 29, 2022

Description

Hi. Using MaskedBehavior on Entry causes caret to behave incorrectly both on Android and iOS. It goes to the end after changing something in the middle of Entry's input.

Mask with " "

Changing something in the middle of an Entry holding a Mask containing " " sign (for example, removing a character or typing one) always causes the cursor to go to the end of the current Entry's input.

Example: I have a Mask like: XXXX XXXX XXXX

_ _ _ _ - _ _ _ _ - _ _ _ _

I'm entering a few numbers, my cursor is at the end of the input:
0123 4567|

I'm placing the cursor to the position 1:
0|123 4567

I'm typing 9, it is recorded in the correct place, but the cursor goes to the end.
0912 3456 7|

It works the same when I'm removing a character in the middle of input.

Mask with "-"

If a Mask contains "-" sign, typing something in the middle of input is not possible at all, even if number of characters is lower than the number of all characters permitted by this Mask. Removing characters in the middle results in allowing for typing there. Sometimes cursor stays in correct position, sometimes not, I didn't investigate it further since I'm mostly interested in Masks with no "-" sign.

Reproduction Sample

  <StackLayout
       VerticalOptions="Center">
       <Entry 
           Margin="25,0,25,0"
           Keyboard="Numeric">
           <Entry.Behaviors>
               <xct:MaskedBehavior Mask="XXXX-XXXX-XXXX"/>
           </Entry.Behaviors>
       </Entry>
       <Label Text="Masked Entry XXXX-XXXX-XXXX" FontSize="Small" Padding="30,10,30,10"/>
       <Entry 
           Margin="25,0,25,0"
           Keyboard="Numeric">
           <Entry.Behaviors>
               <xct:MaskedBehavior Mask="XXXX XXXX XXXX"/>
           </Entry.Behaviors>
       </Entry>
       <Label Text="Masked Entry XXXX XXXX XXXX" FontSize="Small" Padding="30,10,30,10"/>
   </StackLayout>

Steps to Reproduce

  1. Create an Entry with MaskedBehavior "XXXX XXXX XXXX" and the second one with "XXXX-XXXX-XXXX". Run the project.
  2. Type a few characters into an Entry.
  3. Place cursor somewhere in the middle of the Entry (positions from 0 to input length - 2).
  4. Type a character or remove one.
  5. You'll observe your operation working, but then cursor going to the end of the input.

Expected Behavior

Typing in the middle of an Entry always possible. Caret follows input position when changing something in the middle of an Entry.

Actual Behavior

For masks with "-" sign, it's sometimes not even possible to change something in the middle of an Entry (see gif attached). Caret always goes to the end of an Entry when changing something in the middle of the it.

Basic Information

  • Version with issue: XCT 2.0.2
  • Last known good version: ?
  • IDE: Visual Studio 2019 & 2022
  • Platform Target Frameworks:
    • iOS: 12.5, 15.5
    • Android: 9 and 10
  • Nuget Packages: Xamarin.Essentials 1.7.0, Xamarin.Forms 5.0.0.2291, Xamarin.CommunityToolkit 2.0.2, Xamarin.CommunityToolkit.Markup 2.0.2
  • Affected Devices: Xiaomi Redmi Note 10 Pro, Pixel 2 Pie, iPhone 6 Plus

Reproduction imagery

MaskedXCT

@sjasionowska sjasionowska added the bug Something isn't working. Breaky break. label Jun 29, 2022
@VictorHFerreira
Copy link

i'm facing a issue like this too, but in my case i have a mask "XXX.XXX.XXX-XX", and when i type the fourth letter or number, when it should place a ".", the cursor go back to the beginning of the entry

@JhowDevBR
Copy link

SOLVE?

@Reanii
Copy link

Reanii commented Jan 4, 2024

solution?

@JhowDevBR
Copy link

yep.
add event TextChanged...
in [code-behind] add...

if (sender != null)
		{
            (sender as TextField).CursorPosition = (sender as TextField).Text.Length;
        }

@hksharafudheen
Copy link

Any updates for this issue?

@bijington
Copy link
Contributor

Any updates for this issue?

No and with Xamarin going out of support in May I don't think anything will happen here. I would recommend you consider migrating to .NET MAUI

@hksharafudheen
Copy link

@bijington Yes, I am planning of migrating. However, I see the logic is same in MAUI also. Is it handling there?

@bijington
Copy link
Contributor

From what I recall if the issue there is an underlying issue in .NET MAUI which is causing the issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working. Breaky break.
Projects
None yet
Development

No branches or pull requests

6 participants