RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.4k stars 2.17k forks source link

Callback on Init #1397

Open SeanDKendle opened 8 years ago

SeanDKendle commented 8 years ago

Is there no callback on init? There's a callback onComplete which seems to only be run once a value is input, but my page initializes with values in the textboxes, and while they do mask properly, there is no callback that I can then use to call another function on init - that I can find.

I have altered the code in my file to provide myself a callback "onMaskComplete". I could create a pull request for that or if you want to attack it another way, that's fine. Or just let me know that I'm blind and there is a callback of some sort once the plugin has initialized!

Thanks!

SeanDKendle commented 8 years ago

I've made these changes, they may not make any sense, or maybe there is a much better way to approach it:

     function Inputmask(alias, options) {
        var returnVal = this instanceof Inputmask ? ($.isPlainObject(alias) ? options = alias : (options = options || {},
        options.alias = alias), this.el = void 0, this.opts = $.extend(!0, {}, this.defaults, options),
        this.noMasksCache = options && void 0 !== options.definitions, this.userOptions = options || {},
        this.events = {}, void resolveAlias(this.opts.alias, options, this.opts)) : new Inputmask(alias, options);

        this.opts.onAfterMask(this);

        return returnVal;
     }

and in the defaults list:


            onAfterMask: $.noop,
            onBeforeMask: null,
RobinHerbots commented 8 years ago

@SeanKendle ,

Can't you use the onBeforeMask?

SeanDKendle commented 8 years ago

Before mask happens before the masking is applied, I needed the masked value after being masked on page load. It was already filled in the server side code by ASP.net, then masks on pageload, then I needed that value after. If I recall correctly, the onBeforeMask returns the value before being masked.