Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-53182] Uncaught TypeError: Cannot read property 'firstChild' of undefined - updateListBox #3645

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
9 changes: 6 additions & 3 deletions core/src/main/resources/lib/form/select/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ function updateListBox(listBox,url,config) {
config = object(config);
var originalOnSuccess = config.onSuccess;
var l = $(listBox);
var status = findFollowingTR(listBox, "validation-error-area").firstChild.nextSibling;
if (status.firstChild && status.firstChild.getAttribute('data-select-ajax-error')) {
status.innerHTML = "";
var followingTR = findFollowingTR(listBox, "validation-error-area");
if(followingTR!=undefined){
var status = findFollowingTR(listBox, "validation-error-area").firstChild.nextSibling;
Copy link
Member

Choose a reason for hiding this comment

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

Use the existing field instead of repeating findFollowingTR () ?

Copy link
Author

Choose a reason for hiding this comment

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

This has been taken care of by having an exception handler in place Oleg. Ideally, it reduces the overhead of using findFollowingTR () twice.

if (status.firstChild && status.firstChild.getAttribute('data-select-ajax-error')) {
status.innerHTML = "";
}
}
config.onSuccess = function (rsp) {
l.removeClassName("select-ajax-pending");
Expand Down
14 changes: 8 additions & 6 deletions war/src/main/webapp/scripts/hudson-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,17 @@ function findAncestorClass(e, cssClass) {
function findFollowingTR(input, className) {
// identify the parent TR
var tr = input;
while (tr.tagName != "TR")
if(tr.tagName!=undefined){
while (tr.tagName != "TR")
tr = tr.parentNode;
Copy link
Member

Choose a reason for hiding this comment

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

can the parentNode be undefined as well? I believe no, but just in case

Copy link
Author

Choose a reason for hiding this comment

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

Make sense. So, I have added validation even on parentNode.


// then next TR that matches the CSS
do {
// then next TR that matches the CSS
do {
tr = $(tr).next();
} while (tr != null && (tr.tagName != "TR" || !Element.hasClassName(tr,className)));

return tr;
} while (tr != null && (tr.tagName != "TR" || !Element.hasClassName(tr,className)));
return tr;
}
return undefined;
}

function find(src,filter,traversalF) {
Expand Down