Order of events in button.click() is wrong
Brought to you by:
russgold
The button.click() implementation first triggers the
onclick event, then checks if the button is disabled,
and then fires the action. For forms where the onclick
event disables the button to keep this form from being
resubmitted, the action fails because the button is
disabled after the onclick event has been fired. The
order of events should be the same as it would be in a
browser - the button should be checked for disabled
first, then the onclick event should be triggered and
the form action submitted.
Logged In: YES
user_id=1220573
Originator: NO
Dear Al,
excellent bug description.
It's a bit tricky to get this right.
Version 871 for the upcoming 1.7 release has a fix that is tested with the following test in FormSubmitTest.java:
You might want to get that version from the subversion repository trunk.
/**
* test self disabling submit Buttons
* test for bug report [ 1289151 ] Order of events in button.click() is wrong
*/
public void testSelfDisablingSubmitButton() throws Exception {
defineWebPage( "Default", "<form method=GET action = \"Default.html\">" +
"<Input type=submit name='update' onclick='javascript:this.disabled=true;'></form>" +
"</form>" );
WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" );
WebForm form = page.getForms()[0];
SubmitButton[] buttons = form.getSubmitButtons();
assertEquals( "num detected submit buttons", 1, buttons.length );
SubmitButton sb = form.getSubmitButton( "update" );
assertNotNull( "Failed to find update button", sb );
sb.click();
assertTrue( "Disabled button not marked as disabled", sb.isDisabled() );
try {
form.getRequest( sb );
fail( "Allowed to create a request for a disabled button" );
} catch (IllegalStateException e) {}
try {
sb.click();
fail( "Allowed to click a disabled button" );
} catch (IllegalStateException e) {}
}
Yours
Wolfgang
Logged In: YES
user_id=1220573
Originator: NO
The change is now in the subversion repository and will be in the next build