Changeset 12572

Show
Ignore:
Timestamp:
02/20/08 17:25:50 (11 months ago)
Author:
doughays
Message:

Fixes #5327 #5907 !strict. Add onFocus and onBlur hooks to all widgets inheriting from dijit._Widget. Refactored existing _onBlur and _onFocus methods to call this.inherited. Added example user-defined onfocus/onblur methods to a sampling of widget unit tests. Renamed widget event methods like onfocus and onkeyup that will collide with user-defined event handlers.

Location:
dijit/trunk
Files:
29 modified

Legend:

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

    r12437 r12572  
    195195                this._closeDropDown(); 
    196196                // don't focus on button.  the user has explicitly focused on something else. 
     197                this.inherited(arguments); 
    197198        }, 
    198199 
     
    357358        }, 
    358359 
    359         _onBlur: function(evt){ 
     360        _onBlur: function(){ 
    360361                this.inherited(arguments); 
    361362                this._focusedNode = null; 
  • dijit/trunk/form/ComboBox.js

    r12555 r12572  
    7373                hasDownArrow:true, 
    7474 
    75                 // _hasFocus: Boolean 
    76                 //              Represents focus state of the textbox 
    77                 // TODO: get rid of this; it's unnecessary (but currently referenced in FilteringSelect) 
    78                 _hasFocus:false, 
    79  
    8075                templatePath: dojo.moduleUrl("dijit.form", "templates/ComboBox.html"), 
    8176 
     
    8378 
    8479                _lastDisplayedValue: "", 
    85  
    86                 getValue:function(){ 
    87                         // don't get the textbox value but rather the previously set hidden value 
    88                         return dijit.form.TextBox.superclass.getValue.apply(this, arguments); 
    89                 }, 
    9080 
    9181                setDisplayedValue:function(/*String*/ value){ 
     
    168158                },       
    169159                 
    170                 onkeypress: function(/*Event*/ evt){ 
     160                _onKeyPress: function(/*Event*/ evt){ 
    171161                        // summary: handles keyboard events 
    172162 
     
    238228                                        //              _onBlur handler 
    239229                                        if(pw && ( 
    240                                                         newvalue == pw._messages["previousMessage"] || 
    241                                                         newvalue == pw._messages["nextMessage"]) 
     230                                                newvalue == pw._messages["previousMessage"] || 
     231                                                newvalue == pw._messages["nextMessage"]) 
    242232                                        ){ 
    243233                                                break; 
     
    444434                }, 
    445435 
    446                 _onBlur: function(){ 
    447                         // summary: called magically when focus has shifted away from this widget and it's dropdown 
    448                         this._hasFocus=false; 
    449                         this._hasBeenBlurred = true; 
    450                         this._hideResultList(); 
    451                         this._arrowIdle(); 
     436                _setBlurValue: function(){ 
    452437                        // if the user clicks away from the textbox OR tabs away, set the 
    453438                        // value to the textbox value 
    454  
    455439                        // #4617:  
    456440                        //              if value is now more choices or previous choices, revert 
     
    458442                        var newvalue=this.getDisplayedValue(); 
    459443                        var pw = this._popupWidget; 
    460                         if(     pw && ( 
    461                                         newvalue == pw._messages["previousMessage"] || 
    462                                         newvalue == pw._messages["nextMessage"] 
     444                        if(pw && ( 
     445                                newvalue == pw._messages["previousMessage"] || 
     446                                newvalue == pw._messages["nextMessage"] 
    463447                                ) 
    464448                        ){ 
     
    469453                }, 
    470454 
    471                 onfocus:function(/*Event*/ evt){ 
    472                         this._hasFocus=true; 
    473                          
    474                         // update styling to reflect that we are focused 
    475                         this._onMouse(evt); 
     455                _onBlur: function(){ 
     456                        // summary: called magically when focus has shifted away from this widget and it's dropdown 
     457                        this._hideResultList(); 
     458                        this._arrowIdle(); 
     459                        this.inherited(arguments); 
    476460                }, 
    477461 
     
    702686                //              Focus-less div based menu for internal use in ComboBox 
    703687 
    704                 templateString: "<ul class='dijitMenu' dojoAttachEvent='onmousedown,onmouseup,onmouseover,onmouseout' tabIndex='-1' style='overflow:\"auto\";'>" 
     688                templateString: "<ul class='dijitMenu' dojoAttachEvent='onmousedown:_onMouseDown,onmouseup:_onMouseUp,onmouseover:_onMouseOver,onmouseout:_onMouseOut' tabIndex='-1' style='overflow:\"auto\";'>" 
    705689                                +"<li class='dijitMenuItem dijitMenuPreviousButton' dojoAttachPoint='previousButton'></li>" 
    706690                                +"<li class='dijitMenuItem dijitMenuNextButton' dojoAttachPoint='nextButton'></li>" 
     
    789773                }, 
    790774 
    791                 onmousedown: function(/*Event*/ evt){ 
     775                _onMouseDown: function(/*Event*/ evt){ 
    792776                        dojo.stopEvent(evt); 
    793777                }, 
    794778 
    795                 onmouseup: function(/*Event*/ evt){ 
     779                _onMouseUp: function(/*Event*/ evt){ 
    796780                        if(evt.target === this.domNode){ 
    797781                                return; 
     
    811795                }, 
    812796 
    813                 onmouseover: function(/*Event*/ evt){ 
     797                _onMouseOver: function(/*Event*/ evt){ 
    814798                        if(evt.target === this.domNode){ return; } 
    815799                        var tgt = evt.target; 
     
    824808                }, 
    825809 
    826                 onmouseout:function(/*Event*/ evt){ 
     810                _onMouseOut:function(/*Event*/ evt){ 
    827811                        if(evt.target === this.domNode){ return; } 
    828812                        this._blurOptionNode(); 
     
    10691053}); 
    10701054 
     1055 
  • dijit/trunk/form/FilteringSelect.js

    r12149 r12572  
    6161                                //this._setValue("", ""); 
    6262                                //#3285: change CSS to indicate error 
    63                                 if(!this._hasFocus){ this.valueNode.value=""; } 
    64                                 dijit.form.TextBox.superclass.setValue.call(this, undefined, !this._hasFocus); 
     63                                if(!this._focused){ this.valueNode.value=""; } 
     64                                dijit.form.TextBox.superclass.setValue.call(this, undefined, !this._focused); 
    6565                                this._isvalid=false; 
    66                                 this.validate(this._hasFocus); 
     66                                this.validate(this._focused); 
    6767                        }else{ 
    6868                                this._setValueFromItem(result[0], priorityChange); 
     
    148148                        // return: the label that the ComboBox should display 
    149149                        return store.getValue(item, this.searchAttr); 
    150                 }, 
    151  
    152                 onkeyup: function(/*Event*/ evt){ 
    153                         // summary: internal function 
    154  
    155                         // FilteringSelect needs to wait for the complete label before 
    156                         // committing to a reverse lookup 
    157  
    158                         //this.setDisplayedValue(this.textbox.value); 
    159150                }, 
    160151 
  • dijit/trunk/form/NumberTextBox.js

    r12482 r12572  
    1717                editOptions: { pattern: '#.######' }, 
    1818 
    19                 _editing: false, 
    20  
    21                 onfocus: function(evt){ 
    22                         this._editing = true; 
    23 //                      this.inherited(arguments); 
    24                         this.setValue(this.getValue());  
    25                 }, 
    26  
    27                 _onBlur: function(evt){ 
    28                         this._editing = false; 
    29                         this.inherited(arguments); 
     19                _refreshState: function(){ 
     20                        this.setValue(this.getValue(), false);   
    3021                }, 
    3122 
     
    3526                        if(typeof value == "string") { return value; } 
    3627                        if(isNaN(value)){ return ""; } 
    37                         if(this.editOptions && this._editing){ 
     28                        if(this.editOptions && this._focused){ 
    3829                                constraints = dojo.mixin(dojo.mixin({}, this.editOptions), this.constraints); 
    3930                        } 
  • dijit/trunk/form/Slider.js

    r12265 r12572  
    200200        }, 
    201201 
    202         _onBlur: function(){ 
    203                 dijit.form.HorizontalSlider.superclass.setValue.call(this, this.value, true); 
    204         }, 
    205  
    206202        postCreate: function(){ 
    207203                if(this.showButtons){ 
  • dijit/trunk/form/templates/ComboBox.html

    r12555 r12572  
    1313                ><div class="dijitReset dijitInputField" 
    1414                        ><input type="text" autocomplete="off" name="${name}" class='dijitReset' 
    15                         dojoAttachEvent="onkeypress, onkeyup, onfocus, compositionend" 
     15                        dojoAttachEvent="onkeypress:_onKeyPress, onfocus:_update, compositionend" 
    1616                        dojoAttachPoint="textbox,focusNode" waiRole="textbox" waiState="haspopup-true,autocomplete-list" 
    1717                /></div 
  • dijit/trunk/form/templates/Spinner.html

    r11952 r12572  
    2222                ><div class="dijitReset dijitValidationIconText">&Chi;</div 
    2323                ><div class="dijitReset dijitInputField" 
    24                         ><input class='dijitReset' dojoAttachPoint="textbox,focusNode" type="${type}" dojoAttachEvent="onfocus,onkeyup,onkeypress:_onKeyPress" 
     24                        ><input class='dijitReset' dojoAttachPoint="textbox,focusNode" type="${type}" dojoAttachEvent="onfocus:_update,onkeyup:_update,onkeypress:_onKeyPress" 
    2525                                waiRole="spinbutton" autocomplete="off" name="${name}" 
    2626                /></div 
  • dijit/trunk/form/templates/TextBox.html

    r11677 r12572  
    11<input class="dijit dijitReset dijitLeft" dojoAttachPoint='textbox,focusNode' name="${name}" 
    2         dojoAttachEvent='onmouseenter:_onMouse,onmouseleave:_onMouse,onfocus:_onMouse,onblur:_onMouse,onkeyup,onkeypress:_onKeyPress' 
     2        dojoAttachEvent='onmouseenter:_onMouse,onmouseleave:_onMouse,onfocus:_onMouse,onblur:_onMouse,onkeypress:_onKeyPress' 
    33        autocomplete="off" type="${type}" 
    44        /> 
  • dijit/trunk/form/templates/ValidationTextBox.html

    r11952 r12572  
    66                ><div class="dijitReset dijitValidationIconText">&Chi;</div 
    77                ><div class="dijitReset dijitInputField" 
    8                         ><input class="dijitReset" dojoAttachPoint='textbox,focusNode' dojoAttachEvent='onfocus,onblur:_onMouse,onkeyup,onkeypress:_onKeyPress' autocomplete="off" 
     8                        ><input class="dijitReset" dojoAttachPoint='textbox,focusNode' dojoAttachEvent='onfocus:_update,onkeyup:_update,onblur:_onMouse,onkeypress:_onKeyPress' autocomplete="off" 
    99                        type='${type}' name='${name}' 
    1010                /></div 
  • dijit/trunk/form/TextBox.js

    r12193 r12572  
    105105                }, 
    106106 
    107                 // event handlers, you can over-ride these in your own subclasses 
    108                 _onBlur: function(){ 
     107                _setBlurValue: function(){ 
    109108                        this.setValue(this.getValue(), (this.isValid ? this.isValid() : true)); 
    110109                }, 
    111110 
    112                 onkeyup: function(){ 
    113                         // TODO: it would be nice to massage the value (ie: automatic uppercase, etc) as the user types 
    114                         // but this messes up the cursor position if you are typing into the middle of a word, and 
    115                         // also trimming doesn't work correctly (it prevents spaces between words too!) 
    116                         // this.setValue(this.getValue()); 
     111                _onBlur: function(){ 
     112                        this._setBlurValue(); 
     113                        this.inherited(arguments); 
    117114                } 
    118115        } 
  • dijit/trunk/form/ValidationTextBox.js

    r12482 r12572  
    5656                setValue: function(){ 
    5757                        this.inherited(arguments); 
    58                         this.validate(false); 
     58                        this.validate(this._focused); 
    5959                }, 
    6060 
     
    123123                }, 
    124124 
    125                 _hasBeenBlurred: false, 
    126  
    127                 _onBlur: function(){ 
    128                         this._hasBeenBlurred = true; 
    129                         this.validate(false); 
    130                         this.inherited(arguments); 
     125                _refreshState: function(){ 
     126                        this.validate(this._focused); 
    131127                }, 
    132128 
    133129                _update: function(/*Event*/e){ 
    134                         this.validate(true); 
     130                        this._refreshState(); 
    135131                        this._onMouse(e);       // update CSS classes 
    136                 }, 
    137  
    138                 reset: function(){ 
    139                         this.inherited(arguments); 
    140                         this._hasBeenBlurred = false; 
    141132                }, 
    142133 
     
    154145                        var p = this.regExpGen(this.constraints); 
    155146                        this.regExp = p; 
    156                         // make value a string for all types so that form reset works well 
    157  
    158                         this.connect(this, "onfocus", this._update); 
    159                         this.connect(this, "onkeyup", this._update); 
    160147                } 
    161148        } 
  • dijit/trunk/form/_DateTimeTextBox.js

    r12352 r12572  
    119119                        // summary: called magically when focus has shifted away from this widget and it's dropdown 
    120120                        this._close(); 
    121                         this.inherited('_onBlur', arguments); 
     121                        this.inherited(arguments); 
    122122                        // don't focus on <input>.  the user has explicitly focused on something else. 
    123123                }, 
  • dijit/trunk/form/_FormWidget.js

    r12482 r12572  
    235235 
    236236        reset: function(){ 
     237                this._hasBeenBlurred = false; 
    237238                if(this._resetValue !== undefined){ 
    238239                        if(this.setValue && !this._getValueDeprecated){ 
  • dijit/trunk/InlineEditBox.js

    r12495 r12572  
    349349                // summary: 
    350350                //      Called when focus moves outside the editor 
     351                this.inherited(arguments); 
    351352                if(this._exitInProgress){ 
    352353                        // when user clicks the "save" button, focus is shifted back to display text, causing this 
  • dijit/trunk/Menu.js

    r12321 r12572  
    265265 
    266266                this._onBlur = function(){ 
     267                        this.inherited(arguments); 
    267268                        // Usually the parent closes the child widget but if this is a context 
    268269                        // menu then there is no parent 
  • dijit/trunk/tests/form/test_ComboBox.html

    r11973 r12572  
    144144                <option>Wyoming</option> 
    145145        </select> 
    146         onChange:<input id="oc1" disabled value="not fired yet!" autocomplete="off"> 
     146        <br>onChange:<input id="oc1" disabled value="not fired yet!" autocomplete="off"> 
     147        <input type="button" value="Set displayed value to Kentucky" onClick="dijit.byId('setvaluetest').setDisplayedValue('Kentucky')"> 
     148        <input type="button" value="Set displayed value to Canada" onClick="dijit.byId('setvaluetest').setDisplayedValue('Canada')"> 
    147149 
    148150        <hr> 
  • dijit/trunk/tests/form/test_FilteringSelect.html

    r11949 r12572  
    6767                                invalidMessage="Invalid state name" 
    6868                                onChange="dojo.byId('oc1').value=arguments[0]" 
     69                                onFocus="console.log('user focus handler')" 
     70                                onBlur="console.log('user blur handler')" 
    6971                > 
    7072                        <option value="blank"></option> 
  • dijit/trunk/tests/form/test_SimpleTextarea.html

    r12428 r12572  
    1212        </style> 
    1313         
    14         <script type="text/javascript" djConfig="isDebug:false, parseOnLoad: true" 
     14        <script type="text/javascript" djConfig="isDebug:true, parseOnLoad: true" 
    1515                src="../../../dojo/dojo.js"></script> 
    1616 
     
    3333 
    3434                <h2>Plain textarea (rows=5, cols=50)</h2> 
    35                 <textarea dojoType="dijit.form.SimpleTextarea" name="ta2" rows=5 cols=50> 
     35                <textarea dojoType="dijit.form.SimpleTextarea" name="ta2" rows=5 cols=50 
     36                        onFocus="console.log('user focus handler')" 
     37                        onBlur="console.log('user blur handler')" 
     38                > 
    3639                        shichashaw, textarea text baw.                           
    3740                </textarea> 
  • dijit/trunk/tests/form/test_Textarea.html

    r11994 r12572  
    4242                <br><label for="simple">Inline:</label><div name="simpleTextArea" dojoType="dijit.form.Textarea" id="simple" style="width:33%;border:20px solid red;" 
    4343                        onChange="dojo.byId('ocSimple').value=arguments[0]" 
     44                        onFocus="console.log('user focus handler')" 
     45                        onBlur="console.log('user blur handler')" 
    4446                        >this is a very simple resizable text area</div> 
    4547                onChange:<textarea id="ocSimple" readOnly>not fired yet!</textarea> 
  • dijit/trunk/tests/form/test_validate.html

    r12482 r12572  
    6868                                        dojoType="dijit.form.TextBox" 
    6969                                        trim="true" 
     70                                        onfocus="console.log('user onfocus handler')" 
     71                                        onblur="console.log('user onblur handler')" 
    7072                                        onChange="dojo.byId('oc1').value=arguments[0]" 
    7173                                        propercase="true" /> 
  • dijit/trunk/tests/layout/test_TabContainer.html

    r12280 r12572  
    117117        </p> 
    118118 
    119         <div id="ttabs" dojoType="dijit.layout.TabContainer" tabPosition="top" style="width: 100%; height: 10em;"> 
     119        <div id="ttabs" dojoType="dijit.layout.TabContainer" tabPosition="top" style="width: 100%; height: 10em;" 
     120                onfocus="console.log('user focus handler')" 
     121                onblur="console.log('user blur handler')" 
     122        > 
    120123                <div id="ttab1" dojoType="dijit.layout.ContentPane" href="tab1.html" title="First" closable="true"></div> 
    121124                <div id="ttab2" dojoType="dijit.layout.ContentPane" href="tab2.html" refreshOnShow="true" title="Second"></div> 
  • dijit/trunk/tests/test_Dialog.html

    r12449 r12572  
    6060 
    6161<div dojoType="dijit.Dialog" id="dialog1" title="First Dialog" 
     62                onfocus="console.log('user focus handler')" 
     63                onblur="console.log('user blur handler')" 
    6264                execute="alert('submitted w/args:\n' + dojo.toJson(arguments[0], true));"> 
    6365        <table> 
  • dijit/trunk/tests/test_Editor.html

    r12335 r12572  
    4141                <textarea dojoType="dijit.Editor" height="" 
    4242                        extraPlugins="['dijit._editor.plugins.AlwaysShowToolbar']" 
     43                        onfocus="console.log('user focus handler')" 
     44                        onblur="console.log('user blur handler')" 
    4345                        styleSheets="../../dojo/resources/dojo.css" id="thud"> 
    4446                        <p> 
  • dijit/trunk/tests/tree/test_Tree_v1.html

    r12481 r12572  
    3333        <p>Clicking a folder node will open/close it (openOnclick==true), and clicking a leaf node will popup an alert.</p> 
    3434        <div dojoType="dijit.Tree" id="mytree" store="continentStore" query="{type:'continent'}" 
     35                onfocus="console.log('user focus handler')" 
     36                onblur="console.log('user blur handler')" 
    3537                labelAttr="name" label="Continents" openOnClick="true"> 
    3638                <script type="dojo/method" event="onClick" args="item"> 
  • dijit/trunk/Tooltip.js

    r11893 r12572