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

Allow point (".") and comma (",") to be used in keyboard as separator and not only one #1491

Open
MarioLunaSG opened this issue Jan 13, 2025 · 1 comment

Comments

@MarioLunaSG
Copy link

MarioLunaSG commented Jan 13, 2025

🚀 feature request

Currently i can set the thousands separator as point or comma. If i set it to comma, the point button doesn't add a separator.

I suggest that the comma also should be allowed and replaced with the desired separator (.)
I set comma as separator, but point adds a comma and viceversa.

i have to use a separate directive to catch input and add this feature in order to achieve this but mobile is a bit trickyer to do when the directive itself could add this as an optional feature
Thanks!

@lucasousi
Copy link

Hi Mario, while this behavior is not native, I think the inputTrasnformFn (https://jsdaddy.github.io/ngx-mask/#1) may help you. It is easier than "use a separate directive".

Set the follow function in this property:

private swapCommaPeriodSeparator(rawValue: string): string {
  const defaultDecimalSeparator = ',';
  const [lastCharacter] = rawValue.split('').reverse();
  const isLastCharacterSeparator = ['.', ','].includes(lastCharacter);
  const isValidDecimalSeparator = lastCharacter === defaultDecimalSeparator;
  
  if (!isLastCharacterSeparator || isValidDecimalSeparator) {
	  return rawValue;
  }
  
  // Remove the last character and add the decimal separator
  const formattedValue = rawValue.slice(0, -1).concat(defaultDecimalSeparator);
  return formattedValue;
}

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

2 participants