HTMLGuyLLC / jAlert

jQuery alert/modal/lightbox plugin
https://htmlguyllc.github.io/jAlert/
MIT License
76 stars 35 forks source link

Multiple instances when press ENTER key #14

Closed wilmarmacosta closed 9 years ago

wilmarmacosta commented 9 years ago

This issue happens after click a link that opens up a jAlert box and then press ENTER key will open up another instance. It will keep creating an instance as you press ENTER key. The reason for this is because the focus on the link remains active, so if you press enter, its like you clicked the link again.

I made a fix, I hope I done it right but it works for me. I thought you might consider fixing this issue on your next release.

What did was to remove the focus on the active element:

At line 556, I added document.activeElement.blur(); //this is to prevent same link to trigger another instance.

/* If the alert has an element that should be focused by default */

        if(alert.options.autofocus )
        {
            alert.instance.find(alert.options.autofocus).focus();
        } else {
            document.activeElement.blur(); //this is to prevent same link to trigger another instance
        }
HTMLGuyLLC commented 9 years ago

I agree, this would be helpful/useful. I will add it in the next version.

HTMLGuyLLC commented 9 years ago

I'll keep this issue open as a reminder to myself.

HTMLGuyLLC commented 9 years ago

Added in https://github.com/VersatilityWerks/jAlert/commit/0524b38f4957dac575556fab65496532dbc4afd0