I have a form with a textbox that is validated for digits only. The errors are displayed in a jQueryUI modal window. However, when a non-digit is entered into the textbox, I end up with the same error message multiple times. And the more non-numeric values I enter, the more duplicates I get. Any suggestions would be greatly appreciated.
Here is the initial validation

Here is the validation partially fixed

Here is the validation message when I enter a non-numeric value. Notice the multiple Please enter only digits messages.

Here is the code.
var valForm = function(kit_id) {
var form = $("#frm_" + kit_id);
var strErrors = "<ul>";
form.validate({
errorClass: "error-class",
errorElement: "div",
errorPlacement: function(error, element) {
console.log(error);
strErrors += "<li>" + error[0].innerHTML + "</li>";
$("#error_modal").html("");
$("#error_modal").html(strErrors + "</ul>");
}
});
form.find('input[name^="kit_name_"]').each(function () {
$(this).rules("add", {
required: true,
messages: {
required: "Please enter a name."
}
})
});
form.find('input[name^="kit_desc_"]').each(function() {
$(this).rules("add", {
required: true,
messages: {
required: "Please enter a description."
}
});
});
form.find('input[name^="kit_qty_"]').each(function() {
$(this).rules("add", {
required: true,
digits: true,
messages: {
required: "Please enter a quantity."
}
});
});
if (! form.valid()) {
$("#error_modal").dialog().siblings(".ui-dialog-titlebar").remove();
strErrors = "";
} else {
form.submit();
}
};
errorPlacementfunction you append the current error tostrErrors. Nothing ever removes old errors from this, so it just grows and grows.