Author: jkuhnert
Date: Wed Oct 25 13:50:01 2006
New Revision: 467756

URL: http://svn.apache.org/viewvc?view=rev&rev=467756
Log:
Fixes TAPESTRY-1113. Focus was a little tricky wrt to AlertDialogs being 
displayed, but a 
somewhat workable solution seems to fix this by invoking the focusField 
function 
from within the actual Dialog while it is being hidden.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js
    
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js
    
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/widget/AlertDialog.js

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js?view=diff&rev=467756&r1=467755&r2=467756
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js 
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js Wed Oct 
25 13:50:01 2006
@@ -15,6 +15,9 @@
        // property: forms
        // Contains a reference to all registered Tapestry forms in the current 
document.
        forms:{}, // registered form references
+       // property: currentFocus 
+       // Reference to form element/element id of field that should currently 
recieve focus, if any
+       currentFocus:null,
        
        /**
         * Function: focusField
@@ -29,23 +32,39 @@
         *  dojo.html.selectInputText(node).
         */
        focusField:function(field){
-               if (arguments.length < 1) return;
+               if (arguments.length < 1) {return;}
                
-               field = dojo.widget.byId(field);
-               if(field && !dj_undef("focus", field)){
-                       field.focus();
+               var f=dojo.widget.byId(field);
+               if(f && !dj_undef("focus", f)){
+                       f.focus();
                        return;
                } else {
-                       field = dojo.byId(field);
+                       f = dojo.byId(field);
                }
                
-               if (!field) { return; }
+               if (!f) { return; }
+               
+               if(!dj_undef("focus", f)){
+                       f.focus();
+                       return;
+               }
                
                if (field.disabled || field.clientWidth < 1) {
                        return;
                }
                
         dojo.html.selectInputText(field);
+       },
+       
+       /**
+        * Used by AlertDialog to focus the highest priority form field 
+        * that failed validation. This happens because the field needs to 
+        * be focused ~after~ the dialog is hidden.
+        */
+       _focusCurrentField:function(){
+               if(!this.currentFocus){return;}
+               
+               this.focusField(this.currentFocus);
        },
        
        /**

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js?view=diff&rev=467756&r1=467755&r2=467756
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js 
(original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form/validation.js 
Wed Oct 25 13:50:01 2006
@@ -165,9 +165,14 @@
        summarizeErrors:function(form, results, profile){
                var merrs=[];
                var ierrs=[];
+               tapestry.form.currentFocus=null;
+               
                if (results.hasMissing()){
                        var fields=results.getMissing();
                        for (var i=0; i<fields.length; i++){
+                               if(i==0 && !tapestry.form.currentFocus){
+                                       tapestry.form.currentFocus=fields[i];
+                               }
                                if (profile[fields[i]] && 
profile[fields[i]]["required"]){
                                        if 
(dojo.lang.isArray(profile[fields[i]]["required"])) {
                                                for (var z=0; z < 
profile[fields[i]]["required"].length; z++)
@@ -180,6 +185,9 @@
                if (results.hasInvalid()){
                        var fields=results.getInvalid();
                        for (var i=0; i<fields.length; i++){
+                               if(i==0 && !tapestry.form.currentFocus){
+                                       tapestry.form.currentFocus=fields[i];
+                               }
                                if (profile[fields[i]] && 
profile[fields[i]]["constraints"]){
                                        if 
(dojo.lang.isArray(profile[fields[i]]["constraints"])) {
                                                for (var z=0; z < 
profile[fields[i]]["constraints"].length; z++)

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/widget/AlertDialog.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/widget/AlertDialog.js?view=diff&rev=467756&r1=467755&r2=467756
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/widget/AlertDialog.js
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/widget/AlertDialog.js
 Wed Oct 25 13:50:01 2006
@@ -94,6 +94,7 @@
                        dojo.dom.removeNode(this.okButton);
                        
tapestry.widget.AlertDialog.prototype.destroy.call(this);
                        dojo.dom.removeNode(this.bg); 
+                       tapestry.form.focusCurrentField();
                }
        },
        "html"


Reply via email to