Skip to content

Commit

Permalink
Merge pull request #743 from CityOfBoston/develop
Browse files Browse the repository at this point in the history
DIG-2527 Feedback form add phone field
  • Loading branch information
subaha-cob authored Jul 20, 2023
2 parents fc7199c + eaa3041 commit eff25cf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions scripts/components/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var BostonContact = (function () {
var to_address;
var o_message = false;
var o_subject = false;
var o_phone = false;

function initEmailLink(emailLink) {
// Handle the onclick event
Expand Down Expand Up @@ -49,6 +50,7 @@ var BostonContact = (function () {
setToAddress(ev.currentTarget);
setBodyMessage(ev.currentTarget);
setSubject(ev.currentTarget);
setPhone(ev.currentTarget);
setToken(ev.currentTarget);
}
}
Expand Down Expand Up @@ -109,10 +111,13 @@ var BostonContact = (function () {
var email = Boston.childByEl(form, 'bos-contact-email');
var email2 = Boston.childByEl(form, 'bos-contact-email2');
var name = Boston.childByEl(form, 'bos-contact-name');
var phone = Boston.childByEl(form, 'bos-contact-phone');
var subject = Boston.childByEl(form, 'bos-contact-subject');
var message = Boston.childByEl(form, 'bos-contact-message');
var address_to = document.getElementById('contactFormToAddress');
var email_two = document.getElementById('contact-address-two');
var phoneno = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
var phone_input = document.getElementById("contact-phone");
var valid = true;

if (email[0].value == '' || !Boston.emailRE.test(email[0].value)) {
Expand Down Expand Up @@ -160,6 +165,13 @@ var BostonContact = (function () {
if (o_subject && subject[0].value !== o_subject) {
valid = false;
}

if (phone[0].value !== '') {
if (!phone_input.value.match(phoneno)) {
Boston.invalidateField(phone[0], "Please enter a valid phone number");
valid = false;
}
}

return valid;
}
Expand All @@ -183,6 +195,14 @@ var BostonContact = (function () {
}
}

function setPhone(link) {
var phoneField = document.getElementById('contact-phone');
if (o_phone = extract(link.getAttribute('href'), "phone")) {
o_phone = decodeURIComponent(o_phone);
phoneField.value = o_phone;
}
}

function setSubject(link) {
var subjectField = document.getElementById('contact-subject');
if (o_subject = extract(link.getAttribute('href'), "subject")) {
Expand Down

0 comments on commit eff25cf

Please sign in to comment.