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

Backspace are not working correctly #264

Open
sjwen98 opened this issue Feb 12, 2020 · 2 comments
Open

Backspace are not working correctly #264

sjwen98 opened this issue Feb 12, 2020 · 2 comments

Comments

@sjwen98
Copy link

sjwen98 commented Feb 12, 2020

Unable to delete when click on backspace, but only work if the amount is more than thousand, and also if the last digit is not zero.

Example:

  1. if key in 120.00, its not working when click backspace
  2. if key in 1200.00 its working but stop at 120.00
  3. if key in 120.01 its working but it become 120.00 then not more working

update:
if adding prefix or suffix, it will work properly
but i don't want put any prefix and suffix

@sjwen98 sjwen98 changed the title Backspace are not working properly Backspace are not working correctly Feb 12, 2020
@alibarut
Copy link

alibarut commented Sep 29, 2021

Hi, Please add this line

$input.bind("keyup.maskMoney", keydownEvent);

To below this lines.

$input.unbind(".maskMoney");
$input.bind("keypress.maskMoney", keypressEvent);
$input.bind("keydown.maskMoney", keydownEvent);
$input.bind("blur.maskMoney", blurEvent);
$input.bind("focus.maskMoney", focusEvent);
$input.bind("click.maskMoney", clickEvent);
$input.bind("dblclick.maskMoney", doubleClickEvent);
$input.bind("cut.maskMoney", cutPasteEvent);
$input.bind("paste.maskMoney", cutPasteEvent);
$input.bind("mask.maskMoney", mask);

Result

$input.unbind(".maskMoney");
$input.bind("keypress.maskMoney", keypressEvent);
$input.bind("keydown.maskMoney", keydownEvent);
$input.bind("blur.maskMoney", blurEvent);
$input.bind("focus.maskMoney", focusEvent);
$input.bind("click.maskMoney", clickEvent);
$input.bind("dblclick.maskMoney", doubleClickEvent);
$input.bind("cut.maskMoney", cutPasteEvent);
$input.bind("paste.maskMoney", cutPasteEvent);
$input.bind("mask.maskMoney", mask);
$input.bind("keyup.maskMoney", keydownEvent);

And change these lines (startPos -= 1; to startPos -= 0;)

                   if (startPos === endPos) {
                            // backspace
                            if (key === 8) {
                                if (settings.suffix === "") {
                                    startPos -= 1;
                                } else {
                                    // needed to find the position of the last number to be erased
                                    lastNumber = value.split("").reverse().join("").search(/\d/);
                                    startPos = value.length - lastNumber - 1;
                                    endPos = startPos + 1;
                                }
                                //delete
                            } else {
                                endPos += 1;
                            }
                        }

to

                   if (startPos === endPos) {
                            // backspace
                            if (key === 8) {
                                if (settings.suffix === "") {
                                    startPos -= 1;
                                } else {
                                    // needed to find the position of the last number to be erased
                                    lastNumber = value.split("").reverse().join("").search(/\d/);
                                    startPos = value.length - lastNumber - 1;
                                    endPos = startPos + 1;
                                }
                                //delete
                            } else {
                                endPos += 1;
                            }
                        }

@JGuerreroS
Copy link

Gracias, funciona

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

3 participants