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

Added null checks to mitigate exceptions on the '/profiles' pages #9388

Merged
merged 2 commits into from
Feb 13, 2023

Conversation

advay26
Copy link
Member

@advay26 advay26 commented Feb 11, 2023

The /profiles pages use the same js script as the search page, but do not have a searchForm element on the page, so we were getting exceptions from the javascript on the /profiles pages when we tried to reference the form elements.

I've now added checks in the script so that we do not reference anything that doesn't exist on the page.

I also removed a helper method that was not being used by the search page anymore (AddSortByOption()).

@advay26 advay26 requested a review from a team as a code owner February 11, 2023 01:11
submitSearchForm();
});
if (typeof searchForm != "undefined" &&
typeof searchForm.sortby != "undefined") { // /profiles pages use this js file too, but do not have a searchForm element
Copy link
Contributor

Choose a reason for hiding this comment

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

typeof searchForm.sortby != "undefined"

I am not a JS expert. Is that necessary to check this? or just checking 'searchForm' is enough?

Copy link
Member

Choose a reason for hiding this comment

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

Furthermore you can simplify the code by just checking if searchForm is falsy, like if (searchForm).

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed to code to check using just if (searchForm) now. Thanks!

});
if (typeof searchForm != "undefined" &&
typeof searchForm.sortby != "undefined") { // /profiles pages use this js file too, but do not have a searchForm element
searchForm.sortby.addEventListener('change', (e) => {
Copy link
Contributor

@zhhyu zhhyu Feb 11, 2023

Choose a reason for hiding this comment

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

searchForm.sortby.addEventListener

Does that work if we only check once but register them under one block?

Something like:

if (typeof searchForm != "undefined") {
    searchForm.sortby.addEventListener('change', (e) => {
        searchForm.sortby.value = e.target.value;
        submitSearchForm();
    });
    searchForm.addEventListener('submit', submitSearchForm);
    initializeFrameworkAndTfmCheckboxes();
}

Please ignore if it doesn't help.

Copy link
Member Author

Choose a reason for hiding this comment

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

This makes sense and looks much cleaner, so I've put them all in one block. We only need to check if (searchForm) for all of them.

@advay26 advay26 merged commit 6be7bed into dev Feb 13, 2023
@advay26 advay26 deleted the dev-advay26-sbtfm-profilespage branch February 13, 2023 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants