Last active
April 13, 2016 01:58
-
-
Save JimboFromLimbo/70df3e5020354b604706fec3d01fb38f to your computer and use it in GitHub Desktop.
This file contains 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
function checkSection(element, nextElement) { | |
if ($(element).data("required").filled == $(element).data("required").total) { | |
$(nextElement).slideDown('slow'); | |
} else { | |
$(nextElement).slideUp('slow'); | |
} | |
} | |
function checkField(element, parent) { | |
if ($(element).val().length == 0) { | |
if ($(element).hasClass("filled")) { | |
$(parent).data("required").filled--; | |
$(element).removeClass("filled"); | |
} | |
$(element).addClass("failed"); | |
console.log($(parent).data("required").filled); | |
} else { | |
if (!$(element).hasClass("filled")) { | |
if (($(parent).data("required").filled < 7)) { | |
$(parent).data("required").filled++; | |
$(element).addClass("filled"); | |
} | |
} | |
console.log($(parent).data("required").filled); | |
$(element).removeClass("failed"); | |
} | |
} | |
function addRequiredState(element) | |
{ | |
// console.log ('class should be added') | |
console.log(element); | |
$(element).addClass('required'); | |
} | |
function checkForm(fadeoutelement , fadeinelement) { | |
var errors = 0; | |
$('.required').each(function() { | |
if ($(this).val().length == 0) { | |
if ($(this).is(":visible")) { | |
$(this).addClass("failed"); | |
errors++; | |
} | |
} | |
}); | |
if (errors == 0) { | |
$(fadeoutelement).fadeOut(500); | |
$(fadeinelement).delay(500).fadeIn(1500); | |
} else { | |
console.log(errors); | |
} | |
} | |
$('#postal').data("required", {total: $('#postal .required').length, filled: 0}); | |
$('#postal .required').on('keyup click', function() { checkField($(this), $('#postal')); }); | |
$('#postal').on('keyup click', function() { checkSection($(''), $('')); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment