victor-valencia / bootstrap-iconpicker

A simple icon picker
https://victor-valencia.github.com/bootstrap-iconpicker/
MIT License
377 stars 140 forks source link

Existing pickers trigger change event when modal is opened with icons #69

Open audas opened 6 years ago

audas commented 6 years ago

If we have iconpickers on a page, and subsequently load an iconpicker into a modal - then the existing iconpickers all emit a "change" event which causes icons to be inserted all over their target text fields.

It is fired when the javascript is loaded into the modal window - a requirement in my case as it is remote content for a bootstrap modal.

If you set the iconpicker to have no default icon - it does not fire.

However if you change an iconpicker to having an icon - it fires when the javascript is loaded into the modal.

audas commented 6 years ago

Follow up the initiation function

Iconpicker.prototype.setIconset

Calls the select function which fires the change event on line 382

this.select(op.icon);

Commenting this out fixes the problem however it does not set the initial icon (this is the problem). Either the initial icon needs to be set within the setIconset function or a parameter needs to be passed telling the select function not to trigger the change event. Or a global var - nope.

Am passing a second param to the select function telling it if it "setup" or "select" - only trigger the change event if it is a "select".

Works.