Error after update to Editor 2.0 saving Editor values. TypeError: Cannot read property 'length'
Error after update to Editor 2.0 saving Editor values. TypeError: Cannot read property 'length'
Link to test case:
Debugger code (https://debug.datatables.net/elijoh)**:
**Error messages shown:
jquery.js:348 Uncaught TypeError: Cannot read property 'length' of undefined
at Function.each (jquery.js:348)
at Editor._ajax (datatables.js:78912)
at datatables.js:80056
at Editor._event (datatables.js:79313)
at Editor._submit (datatables.js:80047)
at datatables.js:78448
at Editor._event (datatables.js:79313)
at send (datatables.js:78442)
at Editor.submit (datatables.js:78467)
at HTMLDocument.<anonymous> (datatables.js:79476)
Description of problem:
On every edit of an value on the pages this error appears, With Editor 1.9 it is working fine. In the debugger it is the table #dynamic-table-specification
This question has an accepted answers - jump to answer
Answers
Hi @nlooije,
Thanks for letting me know about this error and the debug trace. I can see that you are adding an
extra
parameter (6 for this table) in the Ajax request, but that all looks okay.I'm not sure what your exact build is, so could you confirm what is on the line
datatables.js:78912
for me please? Is it:If so are you setting default values for the Editor Ajax object? If it isn't that, then can you show me your DataTables and Editor initialisation, including any event handlers for this table / editor please?
Thanks,
Allan
Yes line 78912 is indeed
$.each(opts.replacements, function (key, repl) {
It is on every page I have, so also pages without the
extra
parameter.Hereby the initialization of the Editor:
And the datatable is a lot of code because we have made an function to generate the tables on all the pages.
When I use the package of Datatables 1.10.23 with Editor 1.9.6 everything works fine, when I use the package of Datatables 1.10.24 with editor 2.0 I get on every editor.submit the error.
I have solved it with changing the code at line 78912 with:
I think that the
opt.replacements
value is not set with an array, but I can't find where to change my initialisation of the datatable to solve this.Yes - that is a fair fix - thanks for posting it.
I haven't been able to replicate it locally - I'm thinking it might be that some versions of jQuery don't like being passed
undefined
into$.each
. What version of jQuery are you using please? (regardless, I'll put a fix in, but it would be good to know so we can test it).Thanks,
Allan
I'm using indeed an older version of jquery, v2.1.4. I'm not been able yet to update to the 3.xx branch of it.
Excellent - thank you. I’ll try running our test suite against that.
Regards,
Allan