struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Kelly (JIRA)" <j...@apache.org>
Subject [jira] Commented: (STR-1709) [taglib] Add check for nonexistent form field in focus javascript
Date Tue, 05 Jun 2007 06:26:27 GMT

    [ https://issues.apache.org/struts/browse/STR-1709?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41167
] 

Andrew Kelly commented on STR-1709:
-----------------------------------

The code I see output by struts 1.3.9 is

<script type="text/javascript">
  var focusControl = document.forms["BookForm"].elements["bookId"];

  if (focusControl.type != "hidden" && !focusControl.disabled && focusControl.style.display
!= "none") {
     focusControl.focus();
  }
</script>

The output of this should be changed to 

<script type="text/javascript">
  var focusControl = document.forms["BookForm"].elements["bookId"];

  if (focusControl != null && focusControl.type != "hidden" && !focusControl.disabled
&& focusControl.style.display != "none") {
     focusControl.focus();
  }
</script>

The extra check at the start ensure that you don't get "Object has no properties" errors in
the javascript console.

Andy.


> [taglib] Add check for nonexistent form field in focus javascript
> -----------------------------------------------------------------
>
>                 Key: STR-1709
>                 URL: https://issues.apache.org/struts/browse/STR-1709
>             Project: Struts 1
>          Issue Type: Improvement
>          Components: Taglibs
>    Affects Versions: 1.1 Final
>         Environment: Operating System: other
> Platform: Other
>            Reporter: Jonathan Gritzman
>            Assignee: Struts Developers
>            Priority: Minor
>
> After processing the <html:form> tag, some javascript is displayed to force the
> focus to one of the components in the form. However, it is possible that the
> form field may not exist or may become a label if a user doesn't have modify
> access to the field. In this case a javacript error of 'Object Not Found' is
> displayed in a dialog box when the page is loaded.
> The existing javascript focuses into the form field provided the field isn't hidden.
> However, an additional check should be performed to ensure that the form field
> exists. Only then (in addition to the field not being hidden) should the
> javascript move the focus to the field.
> Resolution
> ----------
> In the FormTag's doEndTag() method a call is made to renderFocusJavascript().
> The renderFocusJavascript() method does the following:
>         results.append("  if (focusControl.type != \"hidden\") {");
> Change this to:
> //        Was previously setting the focus to the first text component
> //        if it wasn't a hidden field.
> //        Add an extra check to verify that the field exists.
>         results.append("  if (! focusControl.type === undefined && ");
>         results.append("      focusControl.type != \"hidden\") {");

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


Mime
View raw message