Description
Form.appendDefaultButtonField produces a line like this:
<input type="submit" name="buttons:next" onclick=" var b=Wicket.$('next2'); if (typeof(b.onclick) != 'undefined')
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);
}