From 6df72c0f06d2fa57e6d125af75b4198d2063650c Mon Sep 17 00:00:00 2001 From: Diego Plentz Date: Mon, 2 Mar 2015 00:45:54 -0300 Subject: [PATCH] allowing users to configure multiple fields using data-* properties. fixes #120 --- src/jquery.maskMoney.js | 9 +++++---- test/data_dash_test.js | 11 ++++++++++- test/index.html | 3 ++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/jquery.maskMoney.js b/src/jquery.maskMoney.js index 1d74bed..889ac5f 100644 --- a/src/jquery.maskMoney.js +++ b/src/jquery.maskMoney.js @@ -49,8 +49,8 @@ }); }, - init : function (settings) { - settings = $.extend({ + init : function (parameters) { + parameters = $.extend({ prefix: "", suffix: "", affixesStay: true, @@ -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() { diff --git a/test/data_dash_test.js b/test/data_dash_test.js index 4de6e1b..cdf2338 100644 --- a/test/data_dash_test.js +++ b/test/data_dash_test.js @@ -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"); +}); + diff --git a/test/index.html b/test/index.html index befd8bd..9184b15 100644 --- a/test/index.html +++ b/test/index.html @@ -22,7 +22,8 @@
- + +