I'm searching a while for this and I can't found something that works for me.
I have this checkbox:
<%= Html.CheckBox("cbCodigo") %> <label class="inline" for="Codigo">Codigo</label>
<%= Html.CheckBox("cbNombreCliente") %> <label class="inline" for="NombreCliente">Nombre del cliente</label>
<%= Html.CheckBox("cbCiudad") %> <label class="inline" for="Ciudad">Ciudad</label>
I want to validate that only one is checked when a textbox change, something like this, and use .validate of jQuery, I don't what is the best way for validate this.
tbCodCliente is a textbox that I use as a search parameter, and the checkbox is a parameter or a value for the autocomplete function of the textbox
$('#tbCodCliente').change(function() {
if ($('#cbCodigo').attr('checked', false) &&
$('#cbNombreCliente').attr('checked', false) &&
$('#tbCheckbox').attr('checked', false)) {
// function for validate method
}
});
I trying to validate of this way, but I don't know if it is the best way.
EDIT: I want something like this, but still can found how make it works
('#tbCodCliente').change(function() {
if( $("input:checked").length == 0 ) {
$("#request-form").validate({
rules: {
checkbox: {
required: 'input[type="checkbox"]:checked',
minlength: 1
}
},
messages: {
checkbox: {"Please check at least one."}
}
})
}
});