Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 45 additions & 26 deletions war/src/main/webapp/scripts/hudson-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -1683,47 +1683,66 @@ function rowvgStartEachRow(recursive, f) {
return;
}

var subForms = [];
var start = findInFollowingTR(e, "dropdownList-container");
function buildSubForms(e) {
var subForms = [];
var start = findInFollowingTR(e, "dropdownList-container");

do {
start = start.firstElementChild;
} while (start && !isTR(start));
do {
start = start.firstElementChild;
} while (start && !isTR(start));

if (start && !start.classList.contains("dropdownList-start")) {
start = findFollowingTR(start, "dropdownList-start");
}
while (start != null) {
subForms.push(start);
start = findFollowingTR(start, "dropdownList-start");
if (start && !start.classList.contains("dropdownList-start")) {
start = findFollowingTR(start, "dropdownList-start");
}
while (start != null) {
subForms.push(start);
start = findFollowingTR(start, "dropdownList-start");
}
return subForms;
}

var subForms = buildSubForms(e);
// control visibility
function updateDropDownList() {
for (var i = 0; i < subForms.length; i++) {
var show = e.selectedIndex == i;
var f = subForms[i];

if (show) {
renderOnDemand(f.nextElementSibling);
const idx = i; // capture the index so that it is not mutated in the loop
renderOnDemand(f.nextElementSibling, function () {
const current = e.selectedIndex == idx;
if (!current) {
console.warn(
"renderOnDemandCallback: selection is no longer valid, rebuilding correct DOM",
);
// our form div has changed (but the index is stable) so go and re-get the new domtree
const subForm = buildSubForms(e)[idx];
updateDropDownFormRowVisibility(subForm, false);
Comment on lines 1719 to 1721
Copy link
Member Author

@jtnord jtnord Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for testing these 3 lines where commented out to show the previous console line was printed and the test failed ~ 1:10
Then re introduced and the test passed 100 times in a row

}
});
}
f.rowVisibilityGroup.makeInnerVisible(show);

// TODO: this is actually incorrect in the general case if nested vg uses field-disabled
// so far dropdownList doesn't create such a situation.
f.rowVisibilityGroup.eachRow(
true,
show
? function (e) {
e.removeAttribute("field-disabled");
}
: function (e) {
e.setAttribute("field-disabled", "true");
},
);
updateDropDownFormRowVisibility(f, show);
}
}

function updateDropDownFormRowVisibility(f, show) {
f.rowVisibilityGroup.makeInnerVisible(show);

// TODO: this is actually incorrect in the general case if nested vg uses field-disabled
// so far dropdownList doesn't create such a situation.
f.rowVisibilityGroup.eachRow(
true,
show
? function (e) {
e.removeAttribute("field-disabled");
}
: function (e) {
e.setAttribute("field-disabled", "true");
},
);
}

e.onchange = updateDropDownList;

updateDropDownList();
Expand Down
Loading