Created
April 26, 2016 06:05
-
-
Save JimboFromLimbo/d0a8760e98ce64f3359411f0da2fb415 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 checkField(element, parent) | |
{ | |
if ($(element).attr("type") == "radio") { | |
if ($("input[name=" + $(element).attr("name") + "]:checked").length > 0) { | |
if (!$(element).parent().hasClass("filled")) { | |
if ($(parent).data("required").filled < ($(parent).data("required").total)) { | |
$(parent).data("required").filled++; | |
$(element).parent().addClass("filled"); | |
} | |
} | |
console.log($(parent).data("required").filled); | |
$(element).parent().removeClass("failed-radio"); | |
} | |
} | |
else | |
{ | |
if ($(element).val().length == 0) { | |
console.log('this thing is so fucking broken :*!'); | |
if ($(element).hasClass("filled")) { | |
$(parent).data("required").filled--; | |
$(element).removeClass("filled"); | |
} | |
console.log('atleast it added the class :('); | |
$(element).addClass("failed"); | |
console.log($(parent).data("required").filled); | |
} | |
else { | |
if (!$(element).hasClass("filled")) { | |
if (($(parent).data("required").filled < $(parent).data("required").total)) { | |
$(parent).data("required").filled++; | |
$(element).addClass("filled"); | |
console.log('YAYAYAYYA'); | |
} | |
} | |
console.log($(parent).data("required").filled); | |
$(element).removeClass("failed"); | |
} | |
} | |
} | |
// storing the ids into vars for performance optimization | |
var candidatePersonalDetails = $('#candidate-personal-details-section'); | |
var candidateContactDetails = $('#candidate-contact-section'); | |
var candidateAddressDetails = $('#candidate-address-section'); | |
(candidatePersonalDetails).data('required', {total: (candidatePersonalDetails).find('.required').length, filled: 0}); | |
(candidatePersonalDetails).find('.required').on('keyup click', function() { checkField($(this), (candidatePersonalDetails)); }); | |
(candidatePersonalDetails).on('keyup click', function() { checkSection((candidatePersonalDetails), (candidateContactDetails)); }); | |
$(candidateContactDetails).data("required", {total: $(candidateContactDetails).find('.required').length, filled: 0}); | |
$(candidateContactDetails).find('.required').on('keyup click', function() { checkField($(this), $(candidateContactDetails)); }); | |
$(candidateContactDetails).on('keyup click', function() { checkSection($(candidateContactDetails), $(candidateContactDetails)); }); | |
//address details fieldchecks | |
$(candidateAddressDetails).data("required", {total: $(candidateAddressDetails).find('.required').length, filled: 0}); | |
$(candidateAddressDetails).find('.required').on('keyup click', function() { checkField($(this), $(candidateAddressDetails)); }); | |
$(candidateAddressDetails).on('keyup click', function() { checkSection($(candidateAddressDetails), $('')); }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment