Skip to content

Instantly share code, notes, and snippets.

@JimboFromLimbo
Created April 26, 2016 06:26
Show Gist options
  • Save JimboFromLimbo/46267adb2fef4e178e54f908e60fb772 to your computer and use it in GitHub Desktop.
Save JimboFromLimbo/46267adb2fef4e178e54f908e60fb772 to your computer and use it in GitHub Desktop.
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");
}
}
}
var candidatePersonalDetails = $('#candidate-personal-details-section');
var candidateContactDetails = $('#candidate-contact-section');
var candidateAddressDetails = $('#candidate-address-section');
console.log($(element).attr("type"));
(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)); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment