Ceci est mon exigence: J'ai un tas de sélections de boîtes radio (types de flux de travail). Si l'une des radios est sélectionnée (c'est-à-dire un type particulier de flux de travail sélectionné), je souhaite exécuter une validation personnalisée sur ce point. C'est ce que j'ai essayé, mais ça ne va pas bien. De l'aide?Validation personnalisée jQuery pour une sélection de radio sélectionnée
partie jQuery:
$(document).ready(function() {
// this part is to expand the child radio selection if particular parent workflow selected
$("#concernedDirectorChoice").hide();
$("input[name^=workflowChoice]").change(function(){
if($(this).attr("class")=='chooseDir'){
$("#concernedDirectorChoice").show();
}else{
$("#concernedDirectorChoice").hide(); }
});
// FORM VALIDATION
$.validator.addMethod("dirRequired", function(value, element) {
return this.optional(element) || ($("input[name^=rdDir:checked]").length);
}, "That particular workflow requires a Director to be chosen. Please select Director");
$("#contExpInitiateForm").validate({
debug:true
,rules:{
RenewalNo: {required: true, number: true},
chooseDir: {dirRequired: true},
workflowChoice: {required: true} }
,errorPlacement: function(error, element) {
$('.errorMessageBox').text(error.html()); }
});
});
formulaire HTML partie:
<!-- Pick type of workflow -->
<table class="hr-table" >
<tr> <td class="hr-table-label " colspan=2 >Pick Workflow Type</td> </tr>
<tr>
<td> <input type="radio" name="workflowChoice" value="1"> </input> </td>
<td> Workflow 1 </td>
</tr>
<tr>
<td> <input type="radio" name="workflowChoice" value="2" class="chooseDir"> </input> </td>
<td> Workflow 2 (Dir selection required) </td>
</tr>
<tr>
<td> <input type="radio" name="workflowChoice" value="3"> </input> </td>
<td> Workflow 3 </td>
</tr>
</table>
<!-- Pick Director for Workflow type 2 -->
<table id="concernedDirectorChoice" name="concernedDirectorChoice" >
<tr><td class="hr-table-label" colspan=2 > Choose Concerned Director</td></tr>
<tr>
<td><input type="radio" value='Dir1' name="rdDir" /></td>
<td>Director 1</td>
</tr>
<tr>
<td><input type="radio" value='Dir2' name="rdDir" /></td>
<td>Director 2</td>
</tr>
<tr>
<td><input type="radio" value='Dir3' name="rdDir" /></td>
<td>Director 3</td>
</tr>
</table>
Frère .. vous êtes l'homme! Fonctionne parfaitement. Je ne savais jamais nécessaire pourrait prendre des sélecteurs. C'est un conseil d'or. à votre santé. –