make event listener cleaner
//Event Listeners
form.addEventListener("submit", function (e) {
e.preventDefault();
checkRequired([username, email, password, password2]);
});
make checkRequired function
// Check required fields
function checkReuqired(inputArr) {
inputArr.forEach(function (input) {
if (input.value === "") {
showError(input, `${getFieldName(input)} is required`);
} else {
showSuccess(input);
}
});
}
make getFieldName function
// Get Field Name
function getFieldName(input) {
return input.id.charAt(0).toUpperCase() + input.id.slice(1);
}
'Mini Projects' 카테고리의 다른 글
Form Validator (5) - Logic 정리 (0) | 2020.07.09 |
---|---|
Form Validatior (4) - Check Length, Email & Password match (0) | 2020.07.09 |
Form Validator (2) - Add Simple Validation (0) | 2020.07.09 |
Form Validator (1) HTML & Base CSS (0) | 2020.07.09 |
Knowledge TimeLine (5) Scroll in Animation (0) | 2020.07.08 |