Skip to content

Commit

Permalink
allowing users to configure multiple fields using data-* properties. f…
Browse files Browse the repository at this point in the history
…ixes plentz#120
  • Loading branch information
Diego Plentz committed Mar 2, 2015
1 parent 75a334f commit 6df72c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/jquery.maskMoney.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
});
},

init : function (settings) {
settings = $.extend({
init : function (parameters) {
parameters = $.extend({
prefix: "",
suffix: "",
affixesStay: true,
Expand All @@ -59,13 +59,14 @@
precision: 2,
allowZero: false,
allowNegative: false
}, settings);
}, parameters);

return this.each(function () {
var $input = $(this),
var $input = $(this), settings,
onFocusValue;

// data-* api
settings = $.extend({}, parameters);
settings = $.extend(settings, $input.data());

function getInputSelection() {
Expand Down
11 changes: 10 additions & 1 deletion test/data_dash_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ test("configuring a setting that isn't a single word", function() {
input.attr("data-allow-zero", "true");
input.maskMoney();
input.val("0");
input.trigger("mask").trigger("blur");
input.trigger("mask");
equal(input.val(), "R$0,00", "it works by using dashes-pattern instead of camelCase");
});

test("allow to configure multiple fields using data-* attributes", function() {
var input = $(".multiple-dash").maskMoney();
input.val("12345678");
input.trigger("focus");
equal($("#input3").val(), "R$12.345.678,00", "configure maskMoney using data-* attributes");
equal($("#input4").val(), "U$12,345,678.00", "configure maskMoney using data-* attributes");
});

3 changes: 2 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
<div id="qunit-fixture">
<input type="text" id="input1" class="all"/>
<input type="text" id="input2" class="all"/>
<input type="text" id="input3" data-prefix="R$" data-thousands="." data-decimal=","/>
<input type="text" class="multiple-dash" id="input3" data-prefix="R$" data-thousands="." data-decimal=","/>
<input type="text" class="multiple-dash" id="input4" data-prefix="U$" data-thousands="," data-decimal="."/>
</div>
</body>
</html>

0 comments on commit 6df72c0

Please sign in to comment.