From 65b922d053450ccf84ed7000442d1048d8eaec36 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 21 Oct 2014 11:56:42 -0400 Subject: [PATCH 1/8] Customized default settings, added thousandsStay setting. Set default prefix to "US$ " and default affixStay to "false". Added thousandsStay setting with default value of "false". --- src/jquery.maskMoney.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index ec74807..8222e2d 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -55,14 +55,15 @@ init : function (settings) { settings = $.extend({ - prefix: "", + prefix: "US$ ", suffix: "", - affixesStay: true, + affixesStay: false, thousands: ",", decimal: ".", precision: 2, allowZero: false, - allowNegative: false + allowNegative: false, + thousandsStay: false }, settings); return this.each(function () { @@ -359,6 +360,10 @@ var newValue = $input.val().replace(settings.prefix, "").replace(settings.suffix, ""); $input.val(newValue); } + if (!settings.thousandsStay) { + var newValue = $input.val().replace(settings.thousands, ""); + $input.val(newValue); + } } if ($input.val() !== onFocusValue) { $input.change(); From 7ef8a8e59268d8b242142262e0f059c61830da7a Mon Sep 17 00:00:00 2001 From: Matt Herron Date: Tue, 21 Oct 2014 15:03:07 -0400 Subject: [PATCH 2/8] Changed default settings for more general use. Changed prefix, affixesStay, and thousandsStay default values from personalized to more general purpose settings. --- src/jquery.maskMoney.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index 8222e2d..d698c4f 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -55,15 +55,15 @@ init : function (settings) { settings = $.extend({ - prefix: "US$ ", + prefix: "", suffix: "", - affixesStay: false, + affixesStay: true, thousands: ",", decimal: ".", precision: 2, allowZero: false, allowNegative: false, - thousandsStay: false + thousandsStay: true }, settings); return this.each(function () { From b76da99e33c0f414e25bf65b3315f48a4476b790 Mon Sep 17 00:00:00 2001 From: Matt Herron Date: Tue, 21 Oct 2014 15:23:04 -0400 Subject: [PATCH 3/8] Refactored affix and thousands removal on blur --- src/jquery.maskMoney.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index d698c4f..7ccacb0 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -356,14 +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) { - var newValue = $input.val().replace(settings.thousands, ""); - $input.val(newValue); - } + newValue = newValue.replace(settings.thousands, ""); + } + $input.val(newValue); } if ($input.val() !== onFocusValue) { $input.change(); From 9003df0717027638e9b52cfd9eb707937083e6a8 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 21 Oct 2014 15:30:57 -0400 Subject: [PATCH 4/8] Fixed whitespace --- src/jquery.maskMoney.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index 7ccacb0..dae4cb5 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -356,14 +356,14 @@ $input.val(setSymbol(getDefaultMask())); } } else { - var newValue = $input.val(); + var newValue = $input.val(); if (!settings.affixesStay) { newValue = newValue.replace(settings.prefix, "").replace(settings.suffix, ""); } if (!settings.thousandsStay) { newValue = newValue.replace(settings.thousands, ""); } - $input.val(newValue); + $input.val(newValue); } if ($input.val() !== onFocusValue) { $input.change(); From 76e6a53dc20492f1755c57d5c89a84a3eb627a6e Mon Sep 17 00:00:00 2001 From: Matt Herron Date: Wed, 22 Oct 2014 14:08:32 -0400 Subject: [PATCH 5/8] Replace thousands on global regexp Replaced ALL occurrences of the thousands symbol using a global regexp. --- src/jquery.maskMoney.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index dae4cb5..327dad4 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -360,8 +360,8 @@ if (!settings.affixesStay) { newValue = newValue.replace(settings.prefix, "").replace(settings.suffix, ""); } - if (!settings.thousandsStay) { - newValue = newValue.replace(settings.thousands, ""); + if (!settings.thousandsStay) { + newValue = newValue.replace(new RegExp(settings.thousands,"g"), ""); } $input.val(newValue); } From c4accefddec0909e57db7119c48800a43f58cace Mon Sep 17 00:00:00 2001 From: Matt Herron Date: Wed, 22 Oct 2014 14:12:15 -0400 Subject: [PATCH 6/8] Whitespace formatting --- src/jquery.maskMoney.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index 327dad4..27ee4d2 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -356,14 +356,14 @@ $input.val(setSymbol(getDefaultMask())); } } else { - var newValue = $input.val(); + var newValue = $input.val(); if (!settings.affixesStay) { newValue = newValue.replace(settings.prefix, "").replace(settings.suffix, ""); } if (!settings.thousandsStay) { newValue = newValue.replace(new RegExp(settings.thousands,"g"), ""); } - $input.val(newValue); + $input.val(newValue); } if ($input.val() !== onFocusValue) { $input.change(); From d1e8ba8079c3f345426d04e2a708e04bcfb48952 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 22 Oct 2014 14:23:47 -0400 Subject: [PATCH 7/8] Whitespace formatting --- src/jquery.maskMoney.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index 27ee4d2..0a1be09 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -356,14 +356,14 @@ $input.val(setSymbol(getDefaultMask())); } } else { - var newValue = $input.val(); + var newValue = $input.val(); if (!settings.affixesStay) { newValue = newValue.replace(settings.prefix, "").replace(settings.suffix, ""); } if (!settings.thousandsStay) { newValue = newValue.replace(new RegExp(settings.thousands,"g"), ""); } - $input.val(newValue); + $input.val(newValue); } if ($input.val() !== onFocusValue) { $input.change(); From 32a835e331b29442eab548fb53c08f4aa9861df6 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 22 Oct 2014 14:29:07 -0400 Subject: [PATCH 8/8] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e424961..f58e818 100644 --- a/README.md +++ b/README.md @@ -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