Skip to content

Commit

Permalink
better 0eb9318: preventDefault only if submitForm has called requestS…
Browse files Browse the repository at this point in the history
…ubmit

[JENKINS-65585] avoid double-submit in HtmlUnit when clicking a submit button

[JENKINS-65585] pass the submitter to requestSubmit()

Cherry pick from 8edaa20

Cherry pick from 0eb9318

Cherry pick from b7d8c12
  • Loading branch information
MarkEWaite committed May 18, 2021
1 parent c49afe6 commit 175a840
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
42 changes: 34 additions & 8 deletions war/src/main/webapp/scripts/yui/button/button-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -1974,8 +1974,10 @@ version: 2.9.0

if (p_oEvent.returnValue !== false) {

this.submitForm();

if (this.submitForm() == "requestSubmit") {
// avoid double form submission in HtmlUnit
Event.preventDefault(p_oEvent);
}
}

break;
Expand Down Expand Up @@ -2425,11 +2427,18 @@ version: 2.9.0

var sNodeName = this.NODE_NAME,
oElement = document.createElement(sNodeName);

oElement.innerHTML = "<" + sNodeName + " class=\"first-child\">" +
(p_sType == "link" ? "<a></a>" :
"<button type=\"button\"></button>") + "</" + sNodeName + ">";


var childHTML;
if (p_sType == "link") {
childHTML = "<a></a>";
} else if (p_sType == "submit") {
childHTML = "<button type=\"submit\"></button>";
} else {
childHTML = "<button type=\"button\"></button>";
}
oElement.innerHTML = "<" + sNodeName + " class=\"first-child\">" +
childHTML + "</" + sNodeName + ">";

return oElement;

},
Expand Down Expand Up @@ -2695,7 +2704,24 @@ version: 2.9.0
m_oSubmitTrigger = this;

}


if (oForm.requestSubmit) {
/*
If 'requestSubmit' is defined, use that instead of manually firing the event and then calling 'submit'.
See https://caniuse.com/mdn-api_htmlformelement_requestsubmit
*/
if (this.get("type") == "submit") {
/* Trying very hard to find the right button...
See https://issues.jenkins.io/browse/JENKINS-65585 */
var buttons = this.getElementsByTagName('button');
if (buttons.length == 1 && buttons[0].type == 'submit') {
oForm.requestSubmit(buttons[0]);
return "requestSubmit";
}
}
oForm.requestSubmit();
return "requestSubmit";
}

if (UA.ie && (UA.ie < 9)) {

Expand Down
Loading

0 comments on commit 175a840

Please sign in to comment.