Skip to content

Commit a24153c

Browse files
committed
[JENKINS-76249] Fix form submission when a dropdown changes and the web response is slow
calling renderOnDemand can cause the dom to be manipulated aynchronouslyi due to function calls going to the Jenkins server (e.g. stapler/bound/xxx/render). When this occurs if there is a subsequent change to the dropdown selection before this completes, when the HTML is finally obtained from Jenkins it is inserted into the DOM, but it is inserted as if it is still the selected option (ie it is not disable for the form). renderOnDemand takes a callback function that will be called when the DOM manipulation is complete, however the updateDropDownList did not pass any function. We now pass a function that manipulates the just added HTML if the selected item is in fact no longer selected.
1 parent a7d3225 commit a24153c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

war/src/main/webapp/scripts/hudson-behavior.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,8 +1705,20 @@ function rowvgStartEachRow(recursive, f) {
17051705
var f = subForms[i];
17061706

17071707
if (show) {
1708-
renderOnDemand(f.nextElementSibling);
1708+
const idx = i;// capture the index so that it is not mutated in the loop
1709+
renderOnDemand(f.nextElementSibling, function(){
1710+
var current = e.selectedIndex == idx;
1711+
if (!current) {
1712+
console.log("**** renderOnDemandCallback, selection no longer valid, form submission would have been corrupted");
1713+
updateDropDownFormRowVisibility(f,false);
1714+
}
1715+
});
17091716
}
1717+
updateDropDownFormRowVisibility(f,show);
1718+
}
1719+
}
1720+
1721+
function updateDropDownFormRowVisibility(f, show) {
17101722
f.rowVisibilityGroup.makeInnerVisible(show);
17111723

17121724
// TODO: this is actually incorrect in the general case if nested vg uses field-disabled
@@ -1721,7 +1733,6 @@ function rowvgStartEachRow(recursive, f) {
17211733
e.setAttribute("field-disabled", "true");
17221734
},
17231735
);
1724-
}
17251736
}
17261737

17271738
e.onchange = updateDropDownList;

0 commit comments

Comments
 (0)