RobinHerbots / Inputmask

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

Parent Form event binding cleanup #1466

Open X-BiLe opened 7 years ago

X-BiLe commented 7 years ago

I have implemented a dynamic grid with several input fields all with masks on them. This grid can be removed based on the selection of another field. The issue i am seeing is that the events bound to the parent form do not get disposed of or recycled if the grid gets removed and recreated. The result is exponential event bindings attached to the Form. As a side note i have attempted to dispose of the input fields directly first, still to no avail.

Any suggestions on what i am doing wrong would be greatly appreciated. i really dont want to have to manually remove all of the bound inputmask form events.

usage: $(".minVolume").inputmask("9[9999999]")

X-BiLe commented 7 years ago

Q&D solution to meet my deadline:

var $form = $("form"), resetEvents = [], submitEvents = [], events = $._data.call($form, $form[0], "events"); for (var r = 0; r < events.reset.length; r++) if (events.reset[r].handler != undefined && events.reset[r].handler.toString().indexOf("new Inputmask") === -1) resetEvents.push(events.reset[r]); for (var s = 0; s < events.submit.length; s++) if (events.submit[s].handler != undefined && events.submit[s].handler.toString().indexOf("new Inputmask") === -1) submitEvents.push(events.submit[s]); events.reset = resetEvents; events.submit = submitEvents;