2016-10-21 5 views
0

次の問題が発生しました。誰かが正しい方向に向けるかどうかは分かります。div要素が隠されているときにjQueryの検証をスキップ

http://192.99.201.241/~alumni/register/に複数のパート登録フォームを作成し、次のコードを使用してフォームをセクションに分割しました。

jQuery(document).ready(function() { 

/* 
    Form 
*/ 
$('.registration-form fieldset:first-child').fadeIn('slow'); 

$('.registration-form input[name="s2member_pro_stripe_checkout[first_name]"], .registration-form input[name="s2member_pro_stripe_checkout[last_name]"], .registration-form input[type="password"], .registration-form input[name="s2member_pro_stripe_checkout[username]"], .registration-form input[name="s2member_pro_stripe_checkout[email]"], .registration-form input[name="s2member_pro_stripe_checkout[custom_fields][degree]"], .registration-form input[name="s2member_pro_stripe_checkout[custom_fields][year]"], .registration-form input[name="s2member_pro_stripe_checkout[custom_fields][dob]"]').on('focus', function() { 
    $(this).removeClass('input-error'); 
}); 

// next step 
$('.registration-form .next').on('click', function() { 
    var parent_fieldset = $(this).parents('fieldset'); 
    var next_step = true; 

    parent_fieldset.find('input[name="s2member_pro_stripe_checkout[first_name]"], input[name="s2member_pro_stripe_checkout[last_name]"], input[name="s2member_pro_stripe_checkout[username]"], input[type="email"], input[type="password"], input[name="s2member_pro_stripe_checkout[custom_fields][degree]"], input[name="s2member_pro_stripe_checkout[custom_fields][year]"], input[name="s2member_pro_stripe_checkout[custom_fields][dob]"]').each(function() { 
     if($(this).val() == "") { 
      $(this).addClass('input-error'); 
      next_step = false; 
     } 
     else { 
      $(this).removeClass('input-error'); 
     } 
    }); 

    if(next_step) { 
     parent_fieldset.fadeOut(400, function() { 
      $(this).next().fadeIn(); 
     }); 
    } 

}); 

// previous step 
$('.registration-form .previous').on('click', function() { 
    $(this).parents('fieldset').fadeOut(400, function() { 
     $(this).prev().fadeIn(); 
    }); 
}); 

}); 

フォームのセクション2にいるときは、あなたが登録したいと思う質問があります。非卒業生のオプションを選択すると、あなたの学位、卒業年、卒業生の番号とLinkedInが非表示になります(これらのフィールドに囲まれたdiv要素はnoneを表示するように設定されます)。しかし、あなたが次へを押すと、あなたの学位と卒業年が必須フィールドであるため、さらに進めることはできません。言い換えれば、私はそれらの2つのフィールドが隠されているときの検証をスキップしたいと思います。

ありがとうございました。

答えて

1

要素が見えたり使用しない.is(「:目に見える」)であるかどうかをチェックすることができますので、あなたの方法でループが

parent_fieldset.find('input[name="s2member_pro_stripe_checkout[first_name]"], input[name="s2member_pro_stripe_checkout[last_name]"], input[name="s2member_pro_stripe_checkout[username]"], input[type="email"], input[type="password"], input[name="s2member_pro_stripe_checkout[custom_fields][degree]"], input[name="s2member_pro_stripe_checkout[custom_fields][year]"], input[name="s2member_pro_stripe_checkout[custom_fields][dob]"]').each(function() { 
     if($(this).val() == "" && $(this).is(':visible')) { 
      $(this).addClass('input-error'); 
      next_step = false; 
     } 
     else { 
      $(this).removeClass('input-error'); 
     } 
    }); 
+0

おかげで男のようになりそうです。それは魅力のように働く。 –

+0

他のユーザーがヘルプを得ることができるように答えを正しいとマークしてください:) –

3

隠しフィールドの検証を削除する最も簡単な方法は、disabled属性を追加することです。

var $div2 = $('div#2'); 
$div2.hide(); 

$('input, select, textarea', $div2).attr('disabled', 'disabled'); 
関連する問題