jQuery-Mask-Plugin icon indicating copy to clipboard operation
jQuery-Mask-Plugin copied to clipboard

Feature: allow watchInputs as options parameter

Open ionutab opened this issue 10 years ago • 7 comments

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!

ionutab avatar Mar 18 '16 11:03 ionutab

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.

igorescobar avatar Mar 20 '16 16:03 igorescobar

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 avatar Jun 26 '17 15:06 avs-doom

@avs-doom If you set $.jMaskGlobals.watchInputs = false right after the plugin load it doesn't work?

igorescobar avatar Jun 26 '17 15:06 igorescobar

Or right before defining your masks.

igorescobar avatar Jun 26 '17 15:06 igorescobar

@avs-doom If you don't know how to do it take a look into this: https://jsfiddle.net/igorescobar/x2mhx0Ld/

igorescobar avatar Jun 26 '17 15:06 igorescobar

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 avatar Jun 26 '17 15:06 avs-doom

@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.

igorescobar avatar Jun 26 '17 15:06 igorescobar