Cannot read property 'length' of null, editor with multiple field (chosen plugins)
Cannot read property 'length' of null, editor with multiple field (chosen plugins)
Hello,
Thanks for your great job on editor.
i'm using editor inline editing mode on a multiple field (with chosen plugins).
var editor = new $.fn.dataTable.Editor( {
ajax: "php/table.role.php",
table: '#table',
fields: [
{
label: "Users:",
name: "e_user[].ID",
type: "chosen",
attr:{multiple:"multiple"}
}
]
} );
$('#table).on( 'click', 'tbody td', function (e) {
var index = $(this).parent('tr').find('td').index($(this));
if(index==3){
editor.inline( this,'e_user[].ID' ,{
submitOnBlur: true,
blurOnBackground: false,
buttons: { label: ' ', fn: function () { this.submit(); } }
});
}
} );
I've got the following error trying to submit the field :
Cannot read property 'length' of null
The error only happens when there is no entry selected in the chosen field :
setData @ jquery.dataTables.js:1361
data.(anonymous function) @ jquery.dataTables.js:1403
(anonymous function) @ dataTables.editor.js:4151
m.extend.each @ jquery_min.js:2
Editor._submit @ dataTables.editor.js:4149
Editor.submit.send @ dataTables.editor.js:3007
Editor.submit @ dataTables.editor.js:3029
user_editor.bubble.buttons.fn @ table.role.js:123
(anonymous function) @ dataTables.editor.js:1792
m.event.dispatch @ jquery_min.js:3
m.event.add.r.handle @ jquery_min.js:3
I figured out that wrapping this loop with an if statement solved my problem : (jquery.dataTables.js: line 1361)
// Traverse each entry in the array setting the properties requested
if (val !=null){
for ( var j=0, jLen=val.length ; j<jLen ; j++ ){
o = {};
setData( o, val[j], innerSrc );
data[ a[i] ].push( o );
}
}
Thanks for the feedback