Form.appendDefaultButtonField produces invalid JavaScript if Ajax is disabled
-----------------------------------------------------------------------------

                 Key: WICKET-1914
                 URL: https://issues.apache.org/jira/browse/WICKET-1914
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 1.3.5, 1.3.4
            Reporter: Matthias Keller


Form.appendDefaultButtonField produces a line like this:
<input type="submit" name="buttons:next" onclick=" var b=Wicket.$('next2'); if 
(typeof(b.onclick) != 'undefined') {  var r = b.onclick.bind(b)(); if (r != 
false) b.click(); } else { b.click(); };  return false;"  />

If Ajax is disabled,  var b=Wicket.$('next2')  is invalid, as Wicket  is not 
defined. I'm not familiar with what the bind() method does or whether it is 
needed or not, but the error is ugly and appears whenever a user tries to 
submit a Form by pressing Enter instead of clicking on the submit button.
My proposed fix uses getElementById to get a reference to the submit component. 
Which requires that the markup ID is present.
This can either be done on the fly inside  appendDefaultButtonField()  or maybe 
better in  setDefaultButton().

Here's the fix that works for me on non-ajax pages:

      protected void appendDefaultButtonField (MarkupStream markupStream, 
ComponentTag openTag) {
                                
                                AppendingStringBuffer buffer = new 
AppendingStringBuffer();

                                // div that is not visible (but not 
display:none either)
                                buffer.append("<div 
style=\"width:0px;height:0px;position:absolute;left:-100px;top:-100px;overflow:hidden\">");

                                // add an empty textfield (otherwise IE doesn't 
work)
                                buffer.append("<input type=\"text\" 
autocomplete=\"false\"/>");

                                // add the submitting component
                                final Component submittingComponent = 
(Component) getDefaultButton();
                                submittingComponent.setOutputMarkupId(true);
                                
                                buffer.append("<input type=\"submit\" name=\"");
                                
buffer.append(getDefaultButton().getInputName());
                                buffer.append("\" onclick=\" var 
b=document.getElementById('");
                                
buffer.append(submittingComponent.getMarkupId());
                                buffer.append("'); if (b) { if 
(typeof(b.onclick) != 'undefined') { var r = b.onclick.bind(b)(); if (r != 
false) b.click(); } else { b.click(); }  return false;}\"");
                                buffer.append(" />");
                                
                                // close div
                                buffer.append("</div>");

                                getResponse().write(buffer);
                        }

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

Reply via email to