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

"prepare" Method Ineffective for Converting Numeric Values to Strings Due to Premature String Check in IMask #1093

Open
honibis opened this issue Nov 17, 2024 · 0 comments

Comments

@honibis
Copy link

honibis commented Nov 17, 2024

When binding to numeric values, IMask throws an error: "value should be string". The issue occurs because the prepare method, which could be used to convert a number to a string, is called after IMask performs the string type check.

In the base.js file, the following code leads to the error:

append(str, flags, tail) {
  if (!isString(str)) throw new Error('value should be string');
  const checkTail = isString(tail) ? new ContinuousTailDetails(String(tail)) : tail;
  if (flags != null && flags.tail) flags._beforeTailState = this.state;
  let details;
  [str, details] = this.doPrepare(str, flags);
}

The string check happens before the prepare method, making it ineffective for converting a number to a string.

To Reproduce

Bind a numeric value to an input element.
Apply IMask with a prepare function to convert the number to a string.
IMask throws the error: "value should be string".
Expected behavior

The prepare method should be called before the string check, allowing it to convert a number to a string or apply toString() to numeric values before the check is made. This would prevent the error from being thrown when working with numeric values.

Environment:

"angular-imask": "^7.6.1"
Angular
Additional context

This issue prevents smooth handling of numeric values, especially when binding to inputs with masks that require the value to be treated as a string. Calling the prepare method before the string check would allow for proper type conversion.

@honibis honibis changed the title String check error is thrown before prepare method "prepare" Method Ineffective for Converting Numeric Values to Strings Due to Premature String Check in IMask Nov 17, 2024
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

No branches or pull requests

1 participant