Changeset 13759

Show
Ignore:
Timestamp:
05/17/08 08:59:40 (2 months ago)
Author:
doughays
Message:

Fixes #6186. Added keydown handler for IE and safari to make sure ESC key fires keypress and is stoppable.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/form/_FormWidget.js

    r13752 r13759  
    300300 
    301301        postCreate: function(){ 
     302                if(dojo.isIE || dojo.isSafari){ // IE won't stop the event with keypress and Safari won't send an ESCAPE to keypress at all 
     303                        this.connect(this.focusNode || this.domNode, "onkeydown", this._onKeyDown); 
     304                } 
    302305                this.setValue(this.value, null); 
    303306        }, 
     
    329332        }, 
    330333 
     334        _onKeyDown: function(e){ 
     335                if(e.keyCode == dojo.keys.ESCAPE && !e.ctrlKey && !e.altKey){ 
     336                        var te; 
     337                        if(dojo.isIE){  
     338                                e.preventDefault(); // default behavior needs to be stopped here since keypress is too late 
     339                                te = document.createEventObject(); 
     340                                te.keyCode = dojo.keys.ESCAPE; 
     341                                te.shiftKey = e.shiftKey; 
     342                                e.srcElement.fireEvent('onkeypress', te); 
     343                        }else if(dojo.isSafari){ // ESCAPE needs help making it into keypress 
     344                                te = document.createEvent('Events'); 
     345                                te.initEvent('keypress', true, true); 
     346                                te.keyCode = dojo.keys.ESCAPE; 
     347                                te.shiftKey = e.shiftKey; 
     348                                e.target.dispatchEvent(te); 
     349                        } 
     350                } 
     351        }, 
     352 
    331353        _onKeyPress: function(e){ 
    332                 if(e.charOrCode == dojo.keys.ESCAPE && !e.shiftKey && !e.ctrlKey && !e.altKey){ 
    333                         if(this._valueChanged()){ 
    334                                 this.undo(); 
    335                                 dojo.stopEvent(e); 
    336                                 return false; 
    337                         } 
    338                 } 
    339                 else if(this.intermediateChanges){ 
     354                if(e.charOrCode == dojo.keys.ESCAPE && !e.ctrlKey && !e.altKey && this._valueChanged()){ 
     355                        this.undo(); 
     356                        dojo.stopEvent(e); 
     357                        return false; 
     358                }else if(this.intermediateChanges){ 
    340359                        var _this = this; 
    341360                        // the setTimeout allows the key to post to the widget input box