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

Add thousandsStay setting. #146

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ The options that you can set are:
* `suffix`: the prefix to be displayed after the value entered by the user(example: "1234.23 €"). default: ''
* `affixesStay`: set if the prefix and suffix will stay in the field's value after the user exits the field. default: true
* `thousands`: the thousands separator. default: ','
* `thousandsStay`: set if the thousands separator will stay in the field's value after the user exits the field. defualt: true
* `decimal`: the decimal separator. default: '.'
* `precision`: how many decimal places are allowed. default: 2
* `allowZero`: use this setting to prevent users from inputing zero. default: false
Expand Down
11 changes: 8 additions & 3 deletions src/jquery.maskMoney.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
decimal: ".",
precision: 2,
allowZero: false,
allowNegative: false
allowNegative: false,
thousandsStay: true
}, settings);

return this.each(function () {
Expand Down Expand Up @@ -355,10 +356,14 @@
$input.val(setSymbol(getDefaultMask()));
}
} else {
var newValue = $input.val();
if (!settings.affixesStay) {
var newValue = $input.val().replace(settings.prefix, "").replace(settings.suffix, "");
$input.val(newValue);
newValue = newValue.replace(settings.prefix, "").replace(settings.suffix, "");
}
if (!settings.thousandsStay) {
newValue = newValue.replace(new RegExp(settings.thousands,"g"), "");
}
$input.val(newValue);
}
if ($input.val() !== onFocusValue) {
$input.change();
Expand Down