Skip to content

Commit

Permalink
additional logic fixes (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgershman authored Mar 21, 2024
1 parent 2223220 commit 4ecb9d9
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions public/src/js/yap-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,31 +440,29 @@ function volunteersValidationHandling(phoneNumberField, volunteerCard)
{
phoneNumberField.addClass("border-danger");
let volunteerName = $(volunteerCard).find(".volunteerName").val();
badOnes.push(volunteerName !== "" ? volunteerName : `Empty Volunteer Card ${$(volunteerCard).find("#volunteerSequence").html()}`);
return false;
return volunteerName !== "" ? volunteerName : `Empty Volunteer Card ${$(volunteerCard).find("#volunteerSequence").html()}`;
}

function saveVolunteers(data_type, countryCode)
{
if (countryCode !== "") {
let allGood = true;
let badOnes = [];
let volunteerCards = $(".volunteerCard").not("#volunteerCardTemplate")
for (let volunteerCard of volunteerCards) {
let phoneNumberField = $(volunteerCard).find(".volunteerPhoneNumber")
try {
if (phoneNumberField.val() === "" || !libphonenumber.parsePhoneNumber(phoneNumberField.val(), countryCode).isValid()) {
allGood = volunteersValidationHandling(phoneNumberField, volunteerCard);
badOnes.push(volunteersValidationHandling(phoneNumberField, volunteerCard));
} else {
phoneNumberField.removeClass("border-danger")
}
} catch (error) {
allGood = volunteersValidationHandling(phoneNumberField, volunteerCard);
badOnes.push(volunteersValidationHandling(phoneNumberField, volunteerCard));
}
}

let alert = $("#volunteer_saved_alert");
if (!allGood) {
if (badOnes.length > 0) {
alert.addClass("alert-danger");
alert.html(`Invalid phone number(s) detected for ${badOnes.join(", ")}. Must contain correct length and country code preceded by +.`);
alert.show();
Expand Down

0 comments on commit 4ecb9d9

Please sign in to comment.