I have used `jQuery.validator.addMethod` to create a custom validate method that will make sure there is at least one row in my data-entry table. Using Firebug, my breakpoint in the method isn't being hit at all. Am I missing something?
Note: I am sure there are problems with the validation method itself, but that is because I can't debug it yet. I am still very much a novice with JavaScript.
Here is what my table looks like:
<table id="editorRows">
...
<tbody class="editorRow">
<tr class="row1">
</tr>
<tr class="row2" style="display: none;">
</tr>
<tr class="row3" style="display:none;">
</tr>
</tbody>
<tbody class="editorRow">
<tr class="row1">
</tr>
<tr class="row2" style="display: none;">
</tr>
<tr class="row3" style="display:none;">
</tr>
</tbody>
</table>
Here is my custom validator:
jQuery.validator.addMethod('required_row', function(val, el) {
var rowCount = $("#editorRows tbody").length;
if (typeof rowCount != "undefined") {
return (rowCount > 0);
} else {
return false;
};
}, "Your request must contain at least one day.");
// Validate the form before submitting
$("form").validate({
rules: {
"#editorRow": { required_row: true }
}
});