I am having a bug in production environment and cannot reproduce it in dev environment, so I thinks it's a matter of browsers.
I have a DataTable filled up by server side proccessing and a custom column that is a checkbox, here's the simplified code:
$("#data-table").DataTable({
"serverSide" : true,
"ajax" : {
"url" : "/list",
"dataSrc" : "data"
},
"columns" : [{
"data" : function(row) {
return '<input class="id-checkbox" type="checkbox" name="ids[]" value="' + row.id + '">';
},
"class" : "text-center",
"orderable" : false
},{
"data" : "name",
"class" : "text-center",
"orderable" : false
}]
});
Then I have some jQuery code than whenever a button is clicked, then get the selected items and post it to the backend server:
$("#button").on("click", function(){
var ids = [];
$('input[type=checkbox]:checked').each(function() {
ids.push(this.value);
});
if (ids.length == 0) {
//POST Ajax request to server
}
});
The thing is that sometimes the ids array is being filled with some ids, and some "on" word, so then my backend explodes as is waiting for an array of Long. Here's an example stacktrace:
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long[]';
nested exception is java.lang.NumberFormatException:
For input string: "109287,109286,109273,108820,on,on"
Does anyone have an idea of what's going on?
input[type=checkbox]:checkedas it is not unique and you could be getting a checkbox not related to what you need.input[name^=ids]:checkedI believe that should work to make it more specific