Skip to content

Commit

Permalink
[JENKINS-72170] fix nested hetero-list entries with mixture of inputs…
Browse files Browse the repository at this point in the history
… and buttons (#8602)

* [JENKINS-72170] fix for nested-hetero-list entries

when a plugin defines the hetero-list elements on its own and still uses
an <input type="button"> element and an inner element is already using
a hetero-list with a <button> element, then the old input wasn't
converted to a button as the inner button was found first.
Avoid this by converting all inputs to buttons before actually looking
up the button.

Recreate the hetero-list.js file to avoid the "No such adjunct found"
warning message

* remove hetero-list.js again
  • Loading branch information
mawinter69 committed Oct 14, 2023
1 parent 3218599 commit 97dde8f
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions war/src/main/js/components/dropdowns/hetero-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ function generateHandles() {
});
}

function convertInputsToButtons(e) {
let oldInputs = e.querySelectorAll("INPUT.hetero-list-add");
oldInputs.forEach((oldbtn) => {
let btn = document.createElement("button");
btn.setAttribute("type", "button");
btn.classList.add("hetero-list-add", "jenkins-button");
btn.innerText = oldbtn.getAttribute("value");
if (oldbtn.hasAttribute("suffix")) {
btn.setAttribute("suffix", oldbtn.getAttribute("suffix"));
}
let chevron = createElementFromHtml(Symbols.CHEVRON_DOWN);
btn.appendChild(chevron);
oldbtn.parentNode.appendChild(btn);
oldbtn.remove();
});
}

function generateButtons() {
behaviorShim.specify(
"DIV.hetero-list-container",
Expand All @@ -31,26 +48,8 @@ function generateButtons() {
return;
}

convertInputsToButtons(e);
let btn = Array.from(e.querySelectorAll("BUTTON.hetero-list-add")).pop();
if (!btn) {
let oldbtn = Array.from(
e.querySelectorAll("INPUT.hetero-list-add"),
).pop();
if (!oldbtn) {
return;
}
btn = document.createElement("button");
btn.setAttribute("type", "button");
btn.classList.add("hetero-list-add", "jenkins-button");
btn.innerText = oldbtn.getAttribute("value");
if (oldbtn.hasAttribute("suffix")) {
btn.setAttribute("suffix", oldbtn.getAttribute("suffix"));
}
let chevron = createElementFromHtml(Symbols.CHEVRON_DOWN);
btn.appendChild(chevron);
oldbtn.parentNode.appendChild(btn);
oldbtn.remove();
}

let prototypes = e.lastElementChild;
while (!prototypes.classList.contains("prototypes")) {
Expand Down

0 comments on commit 97dde8f

Please sign in to comment.