You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
The text was updated successfully, but these errors were encountered:
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
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:
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.
The text was updated successfully, but these errors were encountered: