2009-08-14 9 views
4

jqueryの新機能です。validation pluginを使用して、チェックボックスグループ[] を検証しようとしています。私は このAddMethod()チェックボックスの問題を解決するようだが、私は validate()に新しいメソッド名を適用する方法を説明するコードを見つけることができませんでした。検証関数にAddMethod()を適用する

は、ここで私はあなたのソリューションとの答えを入力し、それを受け入れる必要があります

<script type="text/javascript"> 

jQuery.validator.addMethod('minchecked',function(value, element) { 
      return $(element).filter(':checked').length >= 1; 
}, 'please make a selection'); 

$(document).ready(function(){ 
    $("#onlinesurvey").validate({ 
     rules: { 
     <!== do not know how apply the new method if it does go here ==> 
     } 
    }); 
}); 
</script> 

<html> 
<body> 
<form id="onlinesurvey"> 
<fieldset id="stageone"> 
<label for="q1a"><input type="checkbox" name="q1[]" id="q1a" value="Blue Square Casino" />Blue Square Casino</label> 
<label for="q1b"><input type="checkbox" name="q1[]" id="q1b" value="Paddy Power" />Paddy Power</label> 
<label for="q1c"><input type="checkbox" name="q1[]" id="q1c" value="Sky Vegas" />Sky Vegas</label> 
<label for="q1d"><input type="checkbox" name="q1[]" id="q1d" value="Virgin Casino" />Virgin Casino</label> 
<label for="q1e"><input type="checkbox" name="q1[]" id="q1e" value="Other(s)" />Other(s)</label> 
<label for="q1[]" class="error">Please make a selection</label> 
</div> 
<input type="button" value="next" class="next" /> 
</fieldset> 
</form> 
</body> 
</html> 
+1

を達成しようとしています何の私のコードです。 –

答えて

2
$("#onlinesurvey").validate({ 
    rules: { 
    minchecked: true 
    } 
}); 
+0

私はそのコードを適用しましたが、それでも動作しませんでした - 私の混乱はaddMethod "minchecked"という形式のチェックボックスのすべてに適用されます – NiseNise

+0

Hey Josh、 助けてくれてありがとう – NiseNise

関連する問題