#449 Using onclick to disable a submit button does not work

closed-fixed
None
5
2012-09-13
2012-02-14
No

The logic for disabling / enabling a button using the onclick event currently is:

1. SubmitButton.click() called
2. Button.verifyButtonEnabled() is called to verify the button can be clicked
2.1. At this point the enabled / disabled state of the button is remembered
3. Button.doOnClickEvent() is called to execute the onclick. E.g. onclick="button.disabled = true;"
4. SubmitButton.doButtonAction() is called which eventually calls WebForm.getRequest() and WebForm.getSubmitButtonVector()
4.1. getSubmitButtonVector() re-remembers the button state *after* the button has already been clicked, so the remembered state is now switched to disabled
5. WebForm.getRequest() checks the remembered state (!button.wasEnabled()) and throws an exception.

The logic for this appears to have been changed in #1289151. This ticket has a unit test in the comments which was added to the test class, however the sb.click(); line which is in the comment is missing from the test class. The test method is FormSubmitTest.testDisabledSubmitButtonDetection().

To reproduce the issue, just change the code from:

assertNotNull( "Failed to find disabled button", sb );
assertTrue( "Disabled button not marked as disabled", sb.isDisabled() );

To:

assertNotNull( "Failed to find disabled button", sb );
sb.click();
assertTrue( "Disabled button not marked as disabled", sb.isDisabled() );

And run the test-suite.

I believe the step 4.1 above can just be removed to fix this, however am not able to test this at the moment.

Discussion

  • Wolfgang Fahl

    Wolfgang Fahl - 2012-09-13
    • assigned_to: nobody --> wolfgang_fahl
    • status: open --> closed-fixed
     
  • Wolfgang Fahl

    Wolfgang Fahl - 2012-09-13

    Dear Dwayne,

    please check the current subversion state - we are in the process of releasing 1.7.2.

    Yours
    Wolfgang

     

Log in to post a comment.