Skip to content

Commit

Permalink
adding some additional error checking for phone numebrs (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgershman authored Mar 21, 2024
1 parent d551463 commit 2223220
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions public/src/js/yap-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ function includeVolunteers()
includeVolunteer({"volunteer_name": ""});
}

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;
}

function saveVolunteers(data_type, countryCode)
{
if (countryCode !== "") {
Expand All @@ -444,13 +452,14 @@ function saveVolunteers(data_type, countryCode)
let volunteerCards = $(".volunteerCard").not("#volunteerCardTemplate")
for (let volunteerCard of volunteerCards) {
let phoneNumberField = $(volunteerCard).find(".volunteerPhoneNumber")
if (phoneNumberField.val() === "" || !libphonenumber.parsePhoneNumber(phoneNumberField.val(), countryCode).isValid()) {
phoneNumberField.addClass("border-danger")
let volunteerName = $(volunteerCard).find(".volunteerName").val()
badOnes.push(volunteerName !== "" ? volunteerName : `Empty Volunteer Card ${$(volunteerCard).find("#volunteerSequence").html()}`)
allGood = false;
} else {
phoneNumberField.removeClass("border-danger")
try {
if (phoneNumberField.val() === "" || !libphonenumber.parsePhoneNumber(phoneNumberField.val(), countryCode).isValid()) {
allGood = volunteersValidationHandling(phoneNumberField, volunteerCard);
} else {
phoneNumberField.removeClass("border-danger")
}
} catch (error) {
allGood = volunteersValidationHandling(phoneNumberField, volunteerCard);
}
}

Expand Down

0 comments on commit 2223220

Please sign in to comment.