Skip to content

Instantly share code, notes, and snippets.

@dwelch2344
Created November 21, 2018 03:56
Show Gist options
  • Save dwelch2344/476247fded6cf865fe7c860943827d76 to your computer and use it in GitHub Desktop.
Save dwelch2344/476247fded6cf865fe7c860943827d76 to your computer and use it in GitHub Desktop.
function validateBusinessSummaryPage() {
addValidators();
try {
var isValidForm = jQuery("#business_summary_update_company").validate({
rules: {
"business_summary_update_company:duns_number_input": {
number: true,
},
"business_summary_update_company:company_name_input": {
required: true,
maxlength: 90
},
"business_summary_update_company:address_input": {
required: true,
maxlength: 30,
physicalAddress: true
},
"business_summary_update_company:city_input": {
required: true,
maxlength: 30,
validCity: true
},
"business_summary_update_company:state_input": {
required: true
},
"business_summary_update_company:zip_input": {
required: true,
maxlength: 5,
minlength: 5,
number: true
},
"business_summary_update_company:mailing_address_input": {
maxlength: 30
},
"business_summary_update_company:mailing_city_input": {
maxlength: 30
},
"business_summary_update_company:mailing_state_input": {
required: true
},
"business_summary_update_company:year_started_input": {
required: true,
number: true
},
"business_summary_update_company:legal_structure_business_input": {
required: true
},
"business_summary_update_company:telephone_input": {
required: true,
phoneUS: true
}
},
messages: {
"business_summary_update_company:duns_number_input": {
number: "D-U-N-S Number must be a number",
},
"business_summary_update_company:company_name_input": {
required: "Company Name is a required field",
maxlength: "Company Name cannot be more than 90 characters"
},
"business_summary_update_company:address_input": {
required: "Address is a required field",
maxlength: "Address cannot be more than 30 characters"
},
"business_summary_update_company:city_input": {
required: "City is a required field",
maxlength: "City cannot be more than 30 characters"
},
"business_summary_update_company:state_input": {
required: "State is a required field"
},
"business_summary_update_company:zip_input": {
required: "Zip code is a required field",
maxlength: "Please enter a 5-digit zip code",
minlength: "Please enter a 5-digit zip code",
number: "Please enter a 5-digit zip code"
},
"business_summary_update_company:mailing_address_input": {
maxlength: "Mailing Address cannot be more than 30 characters"
},
"business_summary_update_company:mailing_city_input": {
maxlength: "Mailing City cannot be more than 30 characters"
},
"business_summary_update_company:mailing_state_input": {
required: "State is a required field"
},
"business_summary_update_company:year_started_input": {
required: "Year Started is a required field",
number: "Year Started must be a number"
},
"business_summary_update_company:legal_structure_business_input": {
required: "Legal Structure of the Business is a required field"
},
"business_summary_update_company:telephone_input": {
required: "Telephone is a required field",
phoneUS: "Telephone is not a valid phone number (10 digits only)"
}
},
invalidHandler: function(form, validator) {
jQuery("#business_summary_error_lightbox").click();
jQuery.each(validator.errorList, function() {
if (this.element.type == "select-one") {
jQuery(this.element).css("border", "3px solid #FF9A9A");
jQuery(this.element).css("height", "33px");
} else {
var parentElement = this.element.parentElement;
jQuery(parentElement).removeClass("input_bg").addClass("input_bg_error");
}
});
removeValids(form, validator);
},
errorLabelContainer: ".error_label_container",
wrapper: "li",
errorClass: "error_font",
validClass: "success"
}).form();
var validSicCode = validateSicCode();
var sicErrorList = jQuery(".sicError");
var errorContainer = jQuery(".error_label_container")[0];
if (!validSicCode) {
if (isValidForm) {
isValidForm = false;
jQuery("#business_summary_error_lightbox").click();
}
errorContainer.show();
var newElement = document.createElement('li');
if (sicErrorList.length <= 0) {
newElement.setAttribute("class", "error_font sicError");
newElement.innerHTML = "Please add a valid SIC code to the list and/or remove duplicates.";
jQuery(".error_label_container").append(newElement);
}
} else {
// TODO actually fix this? I think it just closes the error container if opened
//if (sicErrorList.length > 0 && jQuery.contains(errorContainer, sicErrorList)) {
//errorContainer.detach(sicErrorList);
//}
}
} catch (err) {
console.log(err);
return false;
}
return isValidForm;
}
function validateSicCode() {
var valid = true;
var removedCounter = 0;
var sicCodeList = jQuery("[id='remove_sic_description']");
valid = sicCodeList.length > 0;
var usedSicList = new Array();
for (var i = 0; i < sicCodeList.length; i++) {
var sicTypeCodeElement = jQuery("#business_summary_update_company\\:sicCodes\\:" + i + "\\:removeCheckbox");
var sicTypeRemoved = sicTypeCodeElement[0].checked;
if (sicTypeRemoved) {
removedCounter++;
}
}
return valid
}
@dwelch2344
Copy link
Author

Line 159 is the true bug – nothing was being returned here so you were hardcoded to be invalid :(

After that, the if statement on 134 also blew up, but I think that's more of a browser quirk or something. Something about sicErrorList.length or the latter statement was blowing up, and I'm pretty sure it just was to hide the error dialog so commented it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment