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

Unable to replace deleted characters to the right of the decimal point with placeholder character. #2801

Open
andrew-esdc opened this issue Jul 3, 2024 · 10 comments

Comments

@andrew-esdc
Copy link

I have a currency input mask with a space for a placeholder instead of a zero.
I want the mask to replace deleted characters on the right of the decimal point with my placeholder rather than zero.
I find that if I set digitsOptional: true the deleted characters are replaced by my placeholder as I want, however the decimal place no longer shows in the mask.
I'm wondering if there is any way to have the deleted characters be replaced with my placeholder, while maintaining the decimal point in the mask.
I can't seem to find a combination of inputmask settings that will make it behave the way I want.
Thank you!

JSFiddle: https://jsfiddle.net/7yrnh13u/12/

Inputmask Version: 5.0.9-beta.50
OS: Windows 10 Enterprise Version 22H2
OS Build # 19045.4529

  • Browser: Edge Version 126.0.2592.81
@Techn1c4l
Copy link

Techn1c4l commented Jul 4, 2024

You can achieve this by using the regex option like this:

$(function() {
  $('#myInput').inputmask('',
  {
      prefix: "$ ",
      rightAlign: false,
      clearMaskOnLostFocus: false,
      placeholder: "",
      regex: '[0-9]+((\\.)?[0-9]*)'
  });
});

@andrew-esdc
Copy link
Author

Not quite. This still replaces the deleted characters with 0, not with my placeholder, which is a blank space.

@Techn1c4l
Copy link

Not quite. This still replaces the deleted characters with 0, not with my placeholder, which is a blank space.

Notice my Inputmask alias is empty, not set to currency like yours.

@andrew-esdc
Copy link
Author

Hmm, yes but when I try your suggestion without the currency, I don't get the prefix or the decimal point showing.

@andrew-esdc
Copy link
Author

I appreciate your advice. Basically I need the mask to show the $ prefix, show the decimal point, but also replace deleted chars with a blank space.

@Techn1c4l
Copy link

I appreciate your advice. Basically I need the mask to show the $ prefix, show the decimal point, but also replace deleted chars with a blank space.

Here you go. This will add the prefix and makes the decimal point and everything after it optional:


$(function() {
  $('#myInput').inputmask('',
  {
      prefix: "$ ",
      rightAlign: false,
      clearMaskOnLostFocus: false,
      placeholder: "",
      regex: '\\$ [0-9]+((\\.)?[0-9]*)'
  });
});

@andrew-esdc
Copy link
Author

Thanks, this is very close to what I need, except that I need the decimal place itself to be non-optional. I will mess around with it from here.

@Techn1c4l
Copy link

Thanks, this is very close to what I need, except that I need the decimal place itself to be non-optional. I will mess around with it from here.

To make it non-optional, set the regex option to regex: '\\$ [0-9]+\\.([0-9]*)'.

@andrew-esdc
Copy link
Author

Incredible. You're a hero. Thanks a lot!

@andrew-esdc
Copy link
Author

So this has allowed me to get things working. Much appreciation.

I will leave the issue open for now because I think that the fact that the currency mask is using the placeholder on delete on the left of the decimal place but not using the placeholder on delete on the right side of the decimal is a bug.

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