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

Small volunteer page fixes #177

Merged
merged 6 commits into from
Jul 15, 2024
Merged

Small volunteer page fixes #177

merged 6 commits into from
Jul 15, 2024

Conversation

struan
Copy link
Member

@struan struan commented Jul 11, 2024

This sorts out a number of small issues with the volunteer management pages.

Fixes #157
Fixes #172
Fixes #173
Fixes #174

@struan struan requested a review from zarino July 11, 2024 13:11
Copy link
Member

@zarino zarino left a comment

Choose a reason for hiding this comment

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

All seems sensible. Just two largely stylistic comments. Feel free to adopt or ignore!

url = url + "?rt=" + $rt.val() + "&s=" + $section.val() + "&ms=" + $session.val()
url = url + "?rt=" + $rt.val() + "&s=" + $section.val() + "&ms=" + $session.val();

if ($id && $id.val()) {
Copy link
Member

Choose a reason for hiding this comment

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

$id $(selector).eq(0)` will always be truthy, even when the selector matches nothing, because it’ll still return a jQuery object, which is truthy.

You probably want either $id.length, or, even simpler, drop the $id && entirely and just rely on $id.val(), since $id.val() will return the falsey undefined if the no elements matched the selector.


if ($rt.val() == "" || $section.val() == "") {
return { results: [] };
}

url = url + "?rt=" + $rt.val() + "&s=" + $section.val() + "&ms=" + $session.val()
url = url + "?rt=" + $rt.val() + "&s=" + $section.val() + "&ms=" + $session.val();
Copy link
Member

Choose a reason for hiding this comment

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

FWIW jQuery has a built-in function to construct query strings like this – $.param(), which has the advantage of also URL-encoding the keys and values, so they’re safe to append to a URL. eg:

url = url + '?' + $.param({
  rt: $rt.val(),
  s: $section.val(),
  ms: $session.val()
});

You could even store everything in a variable at first, then conditionally add your id item (below), and then parametrize them all in one go at the end, eg:

var params = {
  rt: $rt.val(),
  s: $section.val(),
  ms: $session.val()
};

if () {
  params["id"] = $id.val();
}

url = url + '?' + $.param(params);

Or even (replacing the need to declare $session, $section, and $rt up front, since you never use them again anyway):

var params = {
  rt: $fs.find('.field_rt').eq(0).val(),
  s: $fs.find('.field_section').eq(0).val(),
  ms: $fs.find('.field_session').eq(0).val()
};

if () {
  params["id"] = $id.val();
}

url = url + '?' + $.param(params);

Just a thought!

@struan struan merged commit d7881a9 into main Jul 15, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants