Calling field() with unknown fieldName returns error instead of undefined
Calling field() with unknown fieldName returns error instead of undefined
jwa
Posts: 4Questions: 2Answers: 0
Hi!
The API reference for field() states that calling it with an unknown fieldname should return undefined. I want to use that to create a field if it does not yet exist. However, I get an error message ('datatables.min.js:198 Uncaught Unknown field name - test') instead.
This is the code:
editor.on('open', function (e) {
if (!inlineEdit) {
var data = dataTable.row(editor.modifier()).data();
data.vaccinations.forEach(function (vac) {
var name = vac.name.toLowerCase().replace(/\s|\//g, '_');
console.log(editor.field('test'));
if (!editor.field(name)) {
editor.add({
label: vac.name,
name: name,
type: 'switch',
options: {
label: 'Ja'
}
});
}
editor.field(name).set(vac.applied);
});
}
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Thanks for pointing that out. The documentation is wrong I'm afraid there. It does indeed throw an error:
I'll update the docs.
Allan
Thanks, I'll catch the error then.