You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Ted Husted (JIRA)" <ji...@apache.org> on 2006/06/16 22:38:17 UTC

[jira] Created: (WW-1350) Autofocus first enabled field on a form

Autofocus first enabled field on a form
---------------------------------------

         Key: WW-1350
         URL: http://issues.apache.org/struts/browse/WW-1350
     Project: Struts Action 2
        Type: New Feature

    Reporter: Ted Husted
     Fix For: 2.0.0


The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 

References: 
[1] http://www.codeproject.com/jscript/FocusFirstInput.asp
[2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (WW-1350) Autofocus first enabled field on a form

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/struts/browse/WW-1350?page=comments#action_37804 ] 
            
Don Brown commented on WW-1350:
-------------------------------

Ok, so this would involve three new parameters for the form tag: focus, focusIndex, and autoFocus.  The simple form-close.ftl template would be modified to insert the appropriate Javascript.  Does that look like what you were thinking of?

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: http://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>             Fix For: 2.0.0
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (WW-1350) Autofocus first enabled field on a form

Posted by "Chris Mathews (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/struts/browse/WW-1350?page=comments#action_38026 ] 
            
Chris Mathews commented on WW-1350:
-----------------------------------

This is actually very valuable and I have implemented this as a feature in our in-house Web Framework  similar to AppFuse (built on top of WebWork 2.2 and Sitemesh).

I would recommend staying away from a focus attribute on the tag though because it makes it really difficult to implement for the developer that is putting in custom logic to enable/disable fields during form creation.  I would opt to go down more of a css route for disabling/enabling forms/fields "eligible" for focus.

Example Javascript (uses Prototype):

hasClassApplied = function(element, classname) {
  if (element != undefined && (Element.classNames(element) != undefined || Element.classNames(element) != null)) {
    return Element.classNames(element).include(classname);
  }
  return false;
}

focusFirstPageInput = function(excludeFormClassname) {
  for (i = 0; i < document.forms.length; i++) {
    if (!hasClassApplied(document.forms[i], excludeFormClassname)) {
      focusFirstFormInput(document.forms[i]);
      return;
    }
  }
}

focusFirstFormInput = function(form) {
  for (i = 0; i < form.length; i++) {
    if (form[i].type != "hidden" && form[i].type != "submit" && form[i].type != "button") {
      if (!form[i].disabled) {
        Field.activate(form[i]);
        return;
      }
    }
  }
}

We then used an "event" tag (could fit well in ww:head also) that drops an onload event looking similar to:

addLoadEvent( function()  {
    focusFirstPageInput('exclude-from-focus');
});

So basically what this does is puts focus on the first element that is enabled on the first form that isn't marked with the "exclude-from-focus" css class.  You could take it another step and allow exclusion on the individual field level if you really wanted to but I haven't encountered a case where we would need that... typically you either want focus applied to the first active form field or not to the entire form.

Also if you are opening this field focus discussion then you will probably want to add a similar feature for focusing on the first field error if any are found (we did this too).  This is a very similar problem and if you solve one it is easy to solve the other.  The only problem I ran into was that WebWork did not apply an error style to inputs with validation errors... it only marked the input label with an error style.  This was somewhat painful since getting the "for" attribute off the label in order to apply field focus is different in IE and FireFox and just activating the label is not enough.  Ultimately though this was a simple workaround but I would hope in the future WebWork begins to apply css styles a bit more uniformly.


> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: http://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>             Fix For: 2.0.0
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (WW-1350) Autofocus first enabled field on a form

Posted by "Ted Husted (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/struts/browse/WW-1350?page=all ]

Ted Husted updated WW-1350:
---------------------------

    Fix Version/s: 2.0.2
                       (was: 2.0.1)

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: http://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>             Fix For: 2.0.2
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Assigned: (WW-1350) Autofocus first enabled field on a form

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-1350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Musachy Barroso reassigned WW-1350:
-----------------------------------

    Assignee: Musachy Barroso

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: https://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>         Assigned To: Musachy Barroso
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WW-1350) Autofocus first enabled field on a form

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-1350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Musachy Barroso resolved WW-1350.
---------------------------------

    Resolution: Fixed

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: https://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>            Assignee: Musachy Barroso
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-1350) Autofocus first enabled field on a form

Posted by "Frank W. Zammetti (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/struts/browse/WW-1350?page=comments#action_37537 ] 

Frank W. Zammetti commented on WW-1350:
---------------------------------------

If this is something that can be overridden, then cool.  However, it isn't always the case that you want the first enabled, visible form element to by default get focus, so if that was the only way for it to work, I would object.

However, I have an alternate proposal, since the ability to auto-focus is a good one...

First, add an attribute to form elements, perhaps "defaultFocus".  When true, the following script block is rendered:

f=window.onload;if(!f){f=function(){};}f1=function(){document.forms["testform"].middlename.focus();};window.onload=function(){f();f1()};</script>

The value "testform" would of course be replaced with the name of the form, and "middlename" with the name of the field to receive focus.  This way, the developer can determine explicitly which field to give focus to, and you don't have to modify the <body> tag either.

> Autofocus first enabled field on a form
> ---------------------------------------
>
>          Key: WW-1350
>          URL: http://issues.apache.org/struts/browse/WW-1350
>      Project: Struts Action 2
>         Type: New Feature

>     Reporter: Ted Husted
>      Fix For: 2.0.0

>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (WW-1350) Autofocus first enabled field on a form

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-1350?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Don Brown updated WW-1350:
--------------------------

    Fix Version/s:     (was: 2.0.8)
                   2.1.0

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: https://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-1350) Autofocus first enabled field on a form

Posted by "Ted Husted (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/struts/browse/WW-1350?page=all ]

Ted Husted updated WW-1350:
---------------------------

    Fix Version/s: 2.0.x
                       (was: Future)

Tagging features we could implement in the near term. 

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: http://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>             Fix For: 2.0.x
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (WW-1350) Autofocus first enabled field on a form

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-1350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41226 ] 

Musachy Barroso commented on WW-1350:
-------------------------------------

I think adding a "focusElement" attribute to the form tag is enough, that attribute will have the id of the element to be focused, all this will require is executing a simple script when the page loads, am I missing some use case? (I like to keep things simple, sometimes too simple :) )

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: https://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>            Assignee: Musachy Barroso
>            Priority: Minor
>             Fix For: 2.1.0
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-1350) Autofocus first enabled field on a form

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/struts/browse/WW-1350?page=all ]

Don Brown updated WW-1350:
--------------------------


I like this feature, but moving to Future until someone signs up to implement it.

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: http://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>             Fix For: Future
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (WW-1350) Autofocus first enabled field on a form

Posted by "Don Brown (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/struts/browse/WW-1350?page=all ]

Don Brown updated WW-1350:
--------------------------

    Fix Version/s: Future
                       (was: 2.0.2)

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: http://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>             Fix For: Future
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (WW-1350) Autofocus first enabled field on a form

Posted by "Ted Husted (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/struts/browse/WW-1350?page=all ]

Ted Husted updated WW-1350:
---------------------------

    Component: Views

> Autofocus first enabled field on a form
> ---------------------------------------
>
>          Key: WW-1350
>          URL: http://issues.apache.org/struts/browse/WW-1350
>      Project: Struts Action 2
>         Type: New Feature

>   Components: Views
>     Reporter: Ted Husted
>      Fix For: 2.0.0

>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (WW-1350) Autofocus first enabled field on a form

Posted by "Ted Husted (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/struts/browse/WW-1350?page=all ]

Ted Husted updated WW-1350:
---------------------------

    Fix Version/s: 2.0.1
                       (was: 2.0.0)

> Autofocus first enabled field on a form
> ---------------------------------------
>
>                 Key: WW-1350
>                 URL: http://issues.apache.org/struts/browse/WW-1350
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Views
>            Reporter: Ted Husted
>             Fix For: 2.0.1
>
>
> The SAF2 UI tags do not support identifying a field to focus. In SAF1, this is done with a little Javascript. For SAF2, we migth consider using a different Javascript [1] that automatically seeks the first enabled field on the first form. Implementing the feature implies access to the body tag. 
> References: 
> [1] http://www.codeproject.com/jscript/FocusFirstInput.asp
> [2] http://forums.opensymphony.com/thread.jspa?messageID=67350&#67350

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira