micc83 / fontIconPicker

🌈 jQuery fontIconPicker v2 is a small (3.22kb gzipped) jQuery plugin which allows you to include a simple icon picker with search and pagination inside your administration forms.
http://micc83.github.io/fontIconPicker/
MIT License
266 stars 86 forks source link

The select triggers change event on load. #26

Closed malthemilthers closed 6 years ago

malthemilthers commented 8 years ago

Hi, I have been working on implementing the icon selector to a CMS form (WordPress). When a user leaves the form-page, the system checks to see if any changes has happened to the form, and if it finds that changes has happened, it prompts the user with a "are you sure you want to leave the page..." message.

For some reason, the script changes the value from whatever is selected to the same value again, which is considered a ".change" event in Javascript, even though the value is the same. In my case this results in the warning every time someone tries to leave the form-page, even if nothing has changed at all.

Note that this is not the case in version 1.0.0, but is the case in 2.0.0.

Is there a way to get around this? Does the script have to trigger the change-event on load?

For now I have to use version 1.0.0 to get around this, but this doesn't trigger the change-warning, even if it is changed, which I don't quite understand.

Thank you for all your time building this.

micc83 commented 8 years ago

Hello @malthemilthers ,

As I've pointed out in the readme.md many of the features introduced with release 2.0.0 were the result of a collaboration. Unfortunately the developer of those features is not actively following the project anymore and so I can't possible keep up with all the changes he made. I keep using version 1.0.0 myself :)

If you wanna try to figure out where the issue is there are two points where the change event might manually be triggered to the input on line 697 and 701 of jquery.fonticonpicker.js. A fast workaround could be to discard the first event or figure out why it's triggered at all.

Cheers, Alex

malthemilthers commented 8 years ago

Hi Alex, thank you for getting back to me. I completely understand what you're saying, and I apologise for not noticing that in the Readme.

But you actually helped me find the problem. I changed the line at 697 to check for a conditional.

if ( this.element.val() != theIcon) {
    this.element.val((theIcon === '' ? this.settings.emptyIconValue : theIcon )).trigger('change'); 
} 

I don't know if you still do changes to this repo? - would you like me to do a pull request?

micc83 commented 8 years ago

Hello @malthemilthers , Thank you for your feedback. Unfortunately I won't be able to accept new PRs until some good soul steps in to write a test suite for the project but I'll leave the issue open in case someone else had the same issue.

Cheers, Alex

malthemilthers commented 8 years ago

Alright.

Cheers, Malthe

swashata commented 8 years ago

Hello,

Thanks for pointing this out. I will look into it asap.