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

Normalizer does not work when normalized value is empty #20

Open
kiyunkim opened this issue Nov 7, 2024 · 0 comments
Open

Normalizer does not work when normalized value is empty #20

kiyunkim opened this issue Nov 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kiyunkim
Copy link

kiyunkim commented Nov 7, 2024

Describe the bug

Normalizer function does not replace values when normalized value is ''. E.g. When normalizer function strips out numbers, putting in numbers in an input does not empty out the input.

To Reproduce

Steps to reproduce the behavior:

Case 1:

  1. Set normalizer method to a function that removes numbers
normalizer: value => {
  const pattern = new RegExp("[^ A-Za-z'-]", 'gi');
  return value.replace(pattern, '');
}
  1. In the input with the normalizer, type in any numbers. E.g. 23434

Case 2:

  1. Same step as Case 1
  2. In the input, type in any letters and then numbers. E.g. Sdf234

Expected behavior

Input should clear the numbers and display normalized input.

Actual Behavior

Case 1: input does not clear numbers ❌
Case 2: Works as intended; input clears out numbers and leaves letters. ✅

Screenshots

Case 1
image

Case 2
image

Environment:

Tested on Mac Chrome

Additional context

Line 121-124 is probably the culprit here

      // Only change the value if it's different from the normalized one.
      if (normalizedValue && normalizedValue !== field.value) {
        field.value = normalizedValue;
      }

Since normalizedValue is empty, the if statement is not being returned as a true statement

@kiyunkim kiyunkim added the bug Something isn't working label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant