I'm using JQuery validation and a Bootstrap modal in an Aurelia application. The issue that I'm facing is when I hit the submit button on the modal the validation error message doesn't show up but if you click on the input the error message shows up. Why is validation behaving this way?
var html = '<form id="form">';
for (var col in columns) {
if (columns[col].type === 'text' && columns[col].edit) {
html += '<input type="text" value="' + rowData[columns[col].data] + '" name="' + columns[col].data + '" placeholder="' + columns[col].data + '"/><br />';
}
}
html += '<input type="hidden" name="rowIndex" id="rowIndex" value="' + rowIndex + '" />';
html += '<input type="submit" id="update"/></form>';
$('#dialog').html(html);
$("#dialog").modal();
$('body').on('click', '#update', function(e) {
e.preventDefault();
$("#form").validate({
rules: {
name: {
required: true,
minlength: 8
},
place: {
required: true,
minlength: 8
}
},
messages: {
name: {
required: "Please enter some data",
minlength: "Your data must be at least 8 characters"
},
place: {
required: "Please enter some data",
minlength: "Your data must be at least 8 characters"
}
}
});
var data = $('#form').serializeArray();
var rowIndex = $('#rowIndex').val();
var rowData = table.row(rowIndex).data();
var newData = {};
newData['order'] = rowData['order'];
newData['delete'] = rowData['delete'];
for (var d in data) {
newData[data[d]['name']] = data[d]['value'];
}
table.row(rowIndex).data(newData).draw();
});
Here is my JSFiddle if you want more information.