var reg = /\(([0-9]{3})\)\s[0-9]{3}\-[0-9]{4}/;
var constraints = {
first_name : {
presence : true
},
last_name : {
presence : true
},
email : {
presence : true
},
receiving_updates : {
presence : true,
},
phone : {
format : {
pattern : reg,
message : "must be in the following format: (630) 737-9700"
}
}
};
window.onload = function() {
document.getElementById("aasmfForm").addEventListener("submit", function(ev) {
ev.preventDefault();
handleFormSubmit(this);
});
if (window.location.href.indexOf("success=true") > -1) {
document.getElementById("success-container").style.display = "inline-block";
document.getElementById("success-container").style.visibility = "visible";
document.getElementById("form-container").style.display = "none";
document.getElementById("form-container").style.visibility = "hidden";
document.getElementById('openModalButton').click();
}
}
function handleFormSubmit(form) {
var values = validate.collectFormValues(form);
var errors = validate(values, constraints);
showErrors(form, errors || {});
console.log(errors);
if (!errors) {
document.forms["aasmfForm"].submit();
}
}
function showErrors(form, errors) {
var visibleInputs = [];
form.querySelectorAll("input[name], select[name]").forEach(function (input) {
if (!isHidden(input)) {
visibleInputs.push(input);
}
});
visibleInputs.forEach(function (input) {
showErrorsForInput(input, errors && errors[input.name]);
});
}
function isHidden(el) {
var style = window.getComputedStyle(el);
return ((style.display === 'none') || (style.visibility === 'hidden'));
}
function showErrorsForInput(input, errors) {
var formGroup = closestParent(input.parentNode, "form-group");
var messages = formGroup.querySelector(".messages");
resetFormGroup(formGroup);
if (errors) {
formGroup.classList.add("has-error");
errors.forEach(function (error) {
addError(messages, error);
});
} else {
formGroup.classList.add("has-success");
}
}
function closestParent(child, className) {
if (!child || child == document) {
return null
}
if (child.classList.contains(className)) {
return child;
} else {
return closestParent(child.parentNode, className);
}
}
function resetFormGroup(formGroup) {
formGroup.classList.remove("has-error");
formGroup.classList.remove("has-success");
formGroup.querySelectorAll(".help-block.error").forEach( function(el) {
el.parentNode.removeChild(el);
});
}
function addError(messages, error) {
var block = document.createElement("p");
block.classList.add("help-block");
block.classList.add("error");
block.innerHTML = error;
messages.appendChild(block);
}
function showSuccess() {
alert("Success");
}
var preferences = [];
function updatePreference(inputName) {
if (inputName == 'other') {
if (document.getElementById(inputName).checked) {
document.getElementsByClassName('otherUpdates')[0].style.display = "inline-block";
document.getElementsByClassName('otherUpdates')[0].style.visibility = "visible";
} else {
document.getElementsByClassName('otherUpdates')[0].style.display = "none";
document.getElementsByClassName('otherUpdates')[0].style.visibility = "hidden";
}
} else {
if (document.getElementById(inputName).checked) {
preferences.push(document.getElementById(inputName).value);
} else {
var index = preferences.indexOf(document.getElementById(inputName).value);
for (var i = 0; i optgroup[label="Australia"]');
} else if (value == 'BR') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Brazil"]');
} else if (value == 'CA') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Canada"]');
} else if (value == 'CN') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="China"]');
} else if (value == 'IE') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="India"]');
} else if (value == 'IN') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Ireland"]');
} else if (value == 'IT') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Italy"]');
} else if (value == 'MX') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Mexico"]');
} else if (value == 'US') {
var optgroup = document.querySelectorAll('select[name="state_code_select"] > optgroup[label="United States"]');
}
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Australia"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Brazil"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Canada"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="China"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="India"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Ireland"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Italy"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="Mexico"]')[0].style.display = "none";
document.querySelectorAll('select[name="state_code_select"] > optgroup[label="United States"]')[0].style.display = "none";
if (optgroup != undefined && optgroup != "") {
optgroup[0].style.visibility = "visible";
optgroup[0].style.display = "inline-block";
}
}
optgroup[label="Australia"],
optgroup[label="Brazil"],
optgroup[label="Canada"],
optgroup[label="China"],
optgroup[label="Ireland"],
optgroup[label="India"],
optgroup[label="Italy"],
optgroup[label="Mexico"],
optgroup[label="United States"]
{
display: none;
visibility: hidden;
}
#success-container {
display: none;
visibility: hidden;
}
.control-label {
text-align: left !important;
}
.otherUpdates {
display: none;
visibility: hidden;
}
.has-error .help-block {
margin-bottom: 15px !important;
margin-top: 0px !important;
color: red;
}
#form-container input, #form-container textarea, #form-container select {
width: 100%;
}
#form-container .form-check input {
width: auto !important;
}
function timestamp() { var response = document.getElementById("g-recaptcha-response"); if (response == null || response.value.trim() == "") {var elems = JSON.parse(document.getElementsByName("captcha_settings")[0].value);elems["ts"] = JSON.stringify(new Date().getTime());document.getElementsByName("captcha_settings")[0].value = JSON.stringify(elems); } } setInterval(timestamp, 500);
Thank you for subscribing to AASMF emails!