Skip to content

Commit

Permalink
improve dialog form handling (jenkinsci#8701)
Browse files Browse the repository at this point in the history
  • Loading branch information
mawinter69 authored Nov 23, 2023
1 parent f4fe571 commit a9c34d7
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions war/src/main/js/components/dialogs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ Dialog.prototype.appendButtons = function () {
}</button>
</div>`);

this.dialog.appendChild(buttons);
if (this.dialogType === "form") {
this.form.appendChild(buttons);
} else {
this.dialog.appendChild(buttons);
}

this.ok = buttons.querySelector("[data-id=ok]");
this.cancel = buttons.querySelector("[data-id=cancel]");
Expand Down Expand Up @@ -172,25 +176,24 @@ Dialog.prototype.show = function () {
if (this.input != null) {
this.input.focus();
}
if (this.ok != null) {
if (
this.ok != null &&
(this.dialogType != "form" || !this.options.submitButton)
) {
this.ok.addEventListener(
"click",
(e) => {
if (this.dialogType === "form" && this.options.submitButton) {
this.form.submit();
} else {
e.preventDefault();
e.preventDefault();

let value = true;
if (this.dialogType === "prompt") {
value = this.input.value;
}
if (this.dialogType === "form") {
value = new FormData(this.form);
}
this.dialog.remove();
resolve(value);
let value = true;
if (this.dialogType === "prompt") {
value = this.input.value;
}
if (this.dialogType === "form") {
value = new FormData(this.form);
}
this.dialog.remove();
resolve(value);
},
{ once: true },
);
Expand Down

0 comments on commit a9c34d7

Please sign in to comment.