I'm submitting this again here because my Bugzilla patch hasn't gone
anywhere, so I don't know if anyone likes this idea or not. 
Basically, if the cancel button is after the submit button on a form,
and the user hits 'enter' to submit the form, the the cancel button is
the one that is activated, causing the form to be cancelled.  So, I
added a "javascript" property to the cancel button, that when true
causes the javascript button to be rendered as a combination html
button and a hidden text field that are linked through a javascript
onclick event.  It is completely backwards compatible and doesn't
break any current pages (that I know of).

If I'm completely out of line sending this here, I appologize...

Bugzilla link: http://issues.apache.org/bugzilla/show_bug.cgi?id=25860

PATCH
====================

Index: doc/userGuide/struts-html.xml
===================================================================
RCS file: /home/cvspublic/jakarta-struts/doc/userGuide/struts-html.xml,v
retrieving revision 1.67
diff -u -r1.67 struts-html.xml
--- doc/userGuide/struts-html.xml       2 Jan 2004 11:55:38 -0000       1.67
+++ doc/userGuide/struts-html.xml       3 Jan 2004 00:44:06 -0000
@@ -410,6 +410,16 @@
           disabled.
           </info>
         </attribute>
+        <attribute>
+          <name>javascript</name>
+          <required>false</required>
+          <rtexprvalue>true</rtexprvalue>
+          <info>
+          Set to <code>true</code> if this input field should be
+          rendered using a javascript button/hidden field combination
+          as opposed to a submit button.
+          </info>
+        </attribute>
 
         <attribute>
             <name>onblur</name>
Index: src/share/org/apache/struts/taglib/html/CancelTag.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/html/CancelTag.java,v
retrieving revision 1.13
diff -u -r1.13 CancelTag.java
--- src/share/org/apache/struts/taglib/html/CancelTag.java      31 Jul 2003
00:19:04 -0000  1.13
+++ src/share/org/apache/struts/taglib/html/CancelTag.java      3 Jan 2004
00:44:06 -0000
@@ -106,6 +106,12 @@
      */
     protected String value = null;
 
+       /**
+        * Should this be rendered using javascript ?
+        */
+       
+       protected String javascript = null;
+
 
     // ------------------------------------------------------------- Properties
 
@@ -144,6 +150,35 @@
     }
 
 
+
+       /**
+        * return the javascript value
+        */
+       public String getJavascript() {
+               return javascript;
+       }
+
+       /**
+        * @param javascript
+        */
+       public void setJavascript(String javascript) {
+               this.javascript = javascript;
+       }
+
+       /**
+        * 
+        * Return a boolean for if this should be rendered using javascript
+        */
+
+       public boolean renderJavascript() {
+               if (javascript!=null && javascript.toUpperCase().equals("TRUE")) {
+                       return true;
+               }
+               return false;
+       }
+
+
+
     // --------------------------------------------------------- Public Methods
 
 
@@ -192,10 +227,14 @@
 
         // Generate an HTML element
         StringBuffer results = new StringBuffer();
-        results.append("<input type=\"submit\"");
-        results.append(" name=\"");
-        results.append(property);
-        results.append("\"");
+               if (renderJavascript()) {
+                       results.append("<input type=\"button\"");
+               } else {
+                       results.append("<input type=\"submit\"");
+                       results.append(" name=\"");
+                       results.append(property);
+                       results.append("\"");
+               }       
         if (accesskey != null) {
             results.append(" accesskey=\"");
             results.append(accesskey);
@@ -212,12 +251,33 @@
         results.append(prepareEventHandlers());
         results.append(prepareStyles());
         
-        // if no onclick event was provided, put in the cancel script
-        if(results.toString().indexOf("onclick=")==-1){
-          results.append(" onclick=\"bCancel=true;\"");
-        }
-        
-        results.append(getElementClose());
+               if (renderJavascript()) {
+                       String insertStr = "
document.getElementById('"+property+"').value='Cancel'; ";
+                       insertStr += "
document.getElementById('"+property+"').name='"+property+"'; ";
+                       insertStr += " this.form.submit(); ";
+
+                       // if no onclick event was provided, put in the cancel script  
         
+                       if(results.toString().indexOf("onclick=")==-1){
+                         results.append(" onclick=\"bCancel=true; ");
+                         results.append(insertStr);
+                       } else {
+                               int onclickPos = 
results.toString().indexOf("onclick=\"");
+                               int nextQuotePos= 
results.toString().indexOf("\"",onclickPos+10);
+                               results.insert(nextQuotePos,insertStr);
+                       }
+               
+                       results.append(getElementClose());
+       
+                       results.append("<input type=\"hidden\" id=\""+property+"\" 
value=\"\">");
+                } else {
+                       // if no onclick event was provided, put in the cancel script  
         
+       
+                       if(results.toString().indexOf("onclick=")==-1){
+                               results.append(" onclick=\"bCancel=true;\" ");
+                       }
+                       results.append(getElementClose());
+               
+                } 
 
         // Render this element to our writer
         TagUtils.getInstance().write(pageContext, results.toString());
@@ -233,12 +293,14 @@
      */
     public void release() {
 
-       super.release();
-       property = Constants.CANCEL_PROPERTY;
+               super.release();
+               property = Constants.CANCEL_PROPERTY;
         text = null;
-       value = null;
+               value = null;
+               javascript=null;
 
     }
 
 
 }
+

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to