Created
November 25, 2016 13:16
-
-
Save aegiz/724c285d5d048357e2c94d30fe567fea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Check if the different fields are valid | |
* @param {Object} fields.onMailContainer.warningMsgContainer: container to display warning message | |
* @param {Object} fields.onMailContainer.mail: mail to check | |
* @param {Object} fields.onPhoneContainer.warningMsgContainer: container to display warning message | |
* @param {Object} fields.onPhoneContainer.maphoneil: phone to check | |
* @param {Object} fields.onCheckContainer.container: container to display warning message | |
* @param {Object} fields.onCheckContainer.check: checkbox to check (oh oh) | |
* ... | |
* @return {Boolean} passedCheck : return true if successfully passed tests. Else return false | |
*/ | |
var checkConditions = function(fields) { | |
var regNumeric = /^[0-9\(\)\+\.\-\s]+$/, // 1 2 3 4 5 6 7 8 9 0 ( ) + . - espace | |
regMail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, | |
passedCheck = true; | |
if (fields.onMailContainer) { | |
fields.onMailContainer.warningMsgContainer.find(".warningMsg").remove(); | |
if (!regMail.test(fields.onMailContainer.mail)) { | |
fields.onMailContainer.container.css("border" , "1px solid #F7891C"); | |
fields.onMailContainer.warningMsgContainer.append("<div class='warningMsg'>"+ window.PopupLanguage.generic.warningMail + "</div>"); | |
passedCheck = false; | |
} else { | |
fields.onMailContainer.container.css("border" , "1px solid #DDD"); | |
} | |
} | |
if (fields.onPhoneContainer) { | |
fields.onPhoneContainer.warningMsgContainer.find(".warningMsg").remove(); | |
if (!regNumeric.test(fields.onPhoneContainer.phone)) { | |
fields.onPhoneContainer.container.css("border" , "1px solid #F7891C"); | |
fields.onPhoneContainer.warningMsgContainer.append("<div class='warningMsg'>"+ window.PopupLanguage.generic.warningPhone +"</div>"); | |
passedCheck = false; | |
} else { | |
fields.onPhoneContainer.container.css("border" , "1px solid #DDD"); | |
} | |
} | |
if (fields.onCheckContainer) { | |
fields.onCheckContainer.container.find("label, label a").css({ "font-weight" : "300", "color" : "#000000"}); | |
if (fields.onCheckContainer.check.length === 0) { | |
fields.onCheckContainer.container.find("label, label a").css({ "font-weight" : "600", "color" : "#F7891C"}); | |
passedCheck = false; | |
} | |
} | |
if (fields.checkEmail) { | |
if (!regMail.test(fields.checkEmail.mail)) { | |
fields.checkEmail.container.addClass("warningMsg"); | |
passedCheck = false; | |
} else { | |
fields.checkEmail.container.removeClass("warningMsg"); | |
} | |
} | |
if (fields.checkPhone) { | |
if (!regNumeric.test(fields.checkPhone.phone)) { | |
fields.checkPhone.container.addClass("warningMsg"); | |
passedCheck = false; | |
} else { | |
fields.checkPhone.container.removeClass("warningMsg"); | |
} | |
} | |
if (fields.checkEmptyFields) { | |
for (i = 0 ; i < fields.checkEmptyFields.fields.length; i++) { | |
if (fields.checkEmptyFields.fields[i].length < 2) { | |
fields.checkEmptyFields.containers[i].addClass("warningMsg"); | |
passedCheck = false; | |
} else { | |
// In IE8 & 9 the value is by default filled with the placeholder value. So we have to check that the user change it | |
if (($('#wrapper').hasClass('ie8') || $('#wrapper').hasClass('ie9')) && (fields.checkEmptyFields.fields[i] === "Prénom" || fields.checkEmptyFields.fields[i] === "Nom" || fields.checkEmptyFields.fields[i] === "Entreprise")) { | |
fields.checkEmptyFields.containers[i].addClass("warningMsg"); | |
passedCheck = false; | |
} else { | |
fields.checkEmptyFields.containers[i].removeClass("warningMsg"); | |
} | |
} | |
} | |
} | |
return passedCheck; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment