Re: preventDefault() on SELECT element (FF2 & FF3)

Martijn <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
On Wed, Aug 20, 2008 at 1:28 PM,  <[email protected]> wrote:
> Hi all!
> I've got a problem with preventDefault() on some FF widgets. Please
> see the example below (works in Opera 9.5). The checkbox is ok but
> there is no way to prevent the default action on SELECT element. I've
> tried even with document.addEventListener in capture phase. And still
> nothing. Any hints, workarounds?

No hint or workaround from me, but this seems to be
https://bugzilla.mozilla.org/show_bug.cgi?id=291082

Perhaps you could do something like this as a workaround?
event.target.blur();
setTimeout(function(aEl) {aEl.focus()}, 0, event.target);

Regards,
Martijn

> <html>
> <head>
> <script type="text/javascript">
> var KEY_LEFT = 0x25;
> var KEY_RIGHT = 0x27;
>
> function elem_onKey(event)
> {
>        switch (event.keyCode){
>                case KEY_LEFT:
>                        //dump("left\n");
>                        break;
>                case KEY_RIGHT:
>                        //dump("right\n");
>                        break;
>                default:
>                        return true;//propagate
>        }
>        event.preventDefault();
>        event.stopPropagation();
>        return false;//just consume the event when it matches one of defined
> keys
> };
>
> </script>
> </head>
> <body>
> <select onkeydown="elem_onKey(event);"
>                onkeyup="elem_onKey(event);"
>                onkeypress="elem_onKey(event);">
>        <option> a </option>
>        <option> b </option>
>        <option> c </option>
>        <option> d </option>
> </select>
> <br>
> <form>
> <input type="checkbox" onclick="event.preventDefault();"
> onmouseover="event.preventDefault();"
> onmousedown="event.preventDefault();"/>
> <label for="checkbox">Checkbox</label>
> </form>
> </body>
> </html>
> _______________________________________________
> dev-tech-dom mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-dom
>



-- 
Martijn Wargers - Help Mozilla!
http://weblogs.mozillazine.org/qa/
http://wiki.mozilla.org/Mozilla_QA_Community
irc://irc.mozilla.org/qa - /nick mw22
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.