Feature: allow watchInputs as options parameter
Hello, Currently "watchInputs" is a global parameter;
Giving the user the option to call
$('.time').mask('00:00:00',{watchInputs: false});
when the global is true would allow for a more refined control on what to listen for automatically and what not to.
Tried to make some changes in the code but I'm relatively new to JS and don't know how to test this properly.
$.fn.mask = function(mask, options) {
options = options || {};
var selector = this.selector,
local = $.extend(true, $.extend(true, {},$.jMaskGlobals), options),
interval = $.jMaskGlobals.watchInterval,
maskFunction = function() {
if (notSameMaskObject(this, mask, options)) {
return $(this).data('mask', new Mask(this, mask, options));
}
};
$(this).each(maskFunction);
if (selector && selector !== '' && local.watchInputs) {
clearInterval($.maskWatchers[selector]);
$.maskWatchers[selector] = setInterval(function() {
$(document).find(selector).each(maskFunction);
}, interval);
}
return this;
};
Transformed "global" into "local" by cloning $.jsMaskGlobals and overriding locally the values that come as parameters.
I don't know how this will work for the other parameters though.
Thanks!
Hi @ionutab !
Thanks for your suggestion. Check out our new version. What I did is if you pass it locally it will bypass the global preference.
Hi! The code will always return "true".
watchInputs = options.watchInputs || globals.watchInputs Beacause globals.watchInputs is "true", I think it should be "false", otherwise, setting "options.WatchInp" is useless
@avs-doom If you set $.jMaskGlobals.watchInputs = false right after the plugin load it doesn't work?
Or right before defining your masks.
@avs-doom If you don't know how to do it take a look into this: https://jsfiddle.net/igorescobar/x2mhx0Ld/
Yes, I have already done so, but it seems to me not right that I should change the global setting instead of the custom one.
@avs-doom So what you should do is create a functional jsFiddle as I mentioned here: https://github.com/igorescobar/jQuery-Mask-Plugin#bugs
So I can see where the problem relies on my side or yours.