Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazorise TextEdit RegEx issue #4972

Closed
lachlanlhhq opened this issue Sep 5, 2023 · 11 comments
Closed

Blazorise TextEdit RegEx issue #4972

lachlanlhhq opened this issue Sep 5, 2023 · 11 comments

Comments

@lachlanlhhq
Copy link

lachlanlhhq commented Sep 5, 2023

RegEx that used to work is no longer working the same way as it previously did.

Steps to reproduce the behaviour:

  1. Create a Text Edit field
  2. Add MaskType="MaskType.RegEx" and EditMask="^(\d+(.\d{0,2})?|.?\d{1,2})$"
  3. Try to type decimals in the field
  4. The field does not allow decimals

The behaviour expected of the field is to allow decimals to 2 places. This code used to work but it was only noticed recently that it no longer functions anymore. We are using the numeric edit in the mean time with a decimal t value, but this does not allow us to put negative values in easily (you must type a number then add the negative after). We were using the text edit as a way around this and to be able to control the mask type and regex manually, but something has changed.

Example field:
image

Please find below the link to the original bug raised on the abp support forum
https://support.abp.io/QA/Questions/5616/Blazorize-Text-Edit-Control-with-Regex-not-working

Any info on what has caused the issue and how to rectify would be greatly appreciated.

Thanks

@lachlanlhhq lachlanlhhq added the Type: Bug 🐞 Something isn't working label Sep 5, 2023
@stsrki
Copy link
Collaborator

stsrki commented Sep 5, 2023

We will look into it. In the mean time, can you try to use NumericPicker instead of NumericEdit? It should have more control over value editing.

@stsrki stsrki added this to the 1.3 support milestone Sep 5, 2023
@stsrki
Copy link
Collaborator

stsrki commented Oct 14, 2023

I have tested and I cannot reproduce it on my machine. Can you provide us with more information?

  • Blazorise version?
  • Browser?
  • Locale setting?

@latchyy94
Copy link

Blazorise Version: 1.2.4
Browser: Google Chrome
Locale setting: English

In our instance if you type the decimal into the empty field it looks as though it is trying to add it as the text cursor flashes, but no decimal shows up. I tested in edge as well and the same behaviour persists there.

And this is our on text changed method for the field which has been the same since August 2022 when it was implemented and working:

    private void AmountValueChanged(int index, string value)
    {
        if (string.IsNullOrWhiteSpace(value.ToString()))
        {
            Amount = null;
        }
        else
        {
            Amount = Convert.ToDecimal(value);
        }
        StateHasChanged();
    }

@github-actions
Copy link
Contributor

This is an automated message reminding that this issue is expecting the author's answer.

@David-Moreira
Copy link
Contributor

@stsrki

@stsrki
Copy link
Collaborator

stsrki commented Oct 26, 2023

My suspect is that the locale might be what is causing it. I will need to recheck.

@stsrki
Copy link
Collaborator

stsrki commented Nov 2, 2023

I'm still unable to reproduce it. I have tried with several different cultures and locales.

Copy link
Contributor

github-actions bot commented Nov 2, 2023

Hello @lachlanlhhq, thank you for your submission. The issue was labeled "Status: Repro Missing", as you have not provided a way to reproduce the issue quickly. Most problems already solve themselves when isolated, but we would like you to provide us with a reproducible code to make it easier to investigate a possible bug.

@lachlanlhhq
Copy link
Author

lachlanlhhq commented Nov 7, 2023

It seems like the main culprit might be the TextChanged property. I created a new simple solution and added our code to the Index.razor and the issue is occurring. Below is each page and the code that was added there to test. My guess would be the TextChanged has been updated since we first implemented it and that caused the previously working code to no longer work.

Edit: Apologies for the formatting, can't seem to add the razor field code in without it hiding so I have included screenshots instead.

image
image

@stsrki
Copy link
Collaborator

stsrki commented Nov 7, 2023

There is your problem. You're converting the raw Text string value to a number, and it will lose all the details of a string once it is converted. Like the position of a decimal place, padding, and trailing zeros, etc. You must always work with a value that you're binding. In this case, you should bind to a string directly. And then, if needed, you can convert it to a decimal without affecting the original.

<TextEdit @bind-Text="YourFieldName" />

@code {

  string YourFieldName { get; set; }
 
  // add error handling
  decimal? YourAmount => Convert.ToDecimal(YourFieldName);
}

Copy link
Contributor

This is an automated message reminding that this issue is expecting the author's answer.

@github-actions github-actions bot added the Stale label Nov 17, 2023
@stsrki stsrki added this to Support Aug 3, 2024
@stsrki stsrki moved this to ✔ Done in Support Aug 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants