chris feldmann wrote:
> Hi mochinauts.
> I am trying to disable form submission on enter keydown. This snippet
> works on every platform except safai, which even does the visual
> "submit press" animation cue and then submits. Is there some secret
> sauce for safari's enter key?
>
> connect( window, "onload", function(){
>     connect( document, "onkeydown", function( e ){
>                     e.stop();
>                     var key = e.key();
>                     for( p in key ){
>                         logDebug( p + " : " + key[p] );
>                     }
>                     if( key.code == 13 || key.code == 3 ){
>
>                         return false;
>
>                     }
>                 } );

I have an application that makes use of the return key and works fine
in Safari and Firefox. I use the following:

var sendkeyspecial = 0;

var initpage = function () {
        MochiKit.Signal.connect(document, "onkeypress", this, "keypress");
        MochiKit.Signal.connect(document, "onkeydown", this, "keydown");
        MochiKit.Signal.connect(document, "onkeyup", this, "keyup");
};

var isspecialkey = function(e) {
        if(e == 13 || e == 8)
                return 1;
}

this.keypress = function(e) {
  if(e.modifier()['meta'])
        return;
  var code = e.key().code;
  if(code == 0)
        code = sendkeyspecial;
        if(isspecialkey(code) == 1) {
                if(code == 13) { //return
                        e.stop();
                        return;
                }
                if(code == 8) { //backspace
                        e.stop();
                        return;
                }
        }
        e.stop();
}

this.keydown = function(e) {
        sendkeyspecial = e.key().code;
}

this.keyup = function(e) {
        sendkeyspecial = 0;
}

MochiKit.DOM.addLoadEvent(initpage);


This catches all keypresses that don't involve the meta(command) key. I
would probably add special handling for the control key if I was doing
serious development, but this is more of a toy script on my Mac for
now. The sendkeyspecial thing is used to get key repeating to work
properly for special keys in some browsers. 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to