Calling field() with unknown fieldName returns error instead of undefined

Calling field() with unknown fieldName returns error instead of undefined

jwajwa 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

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Thanks for pointing that out. The documentation is wrong I'm afraid there. It does indeed throw an error:

        if ( ! fields[name] ) {
            throw 'Unknown field name - '+name;
        }
    

    I'll update the docs.

    Allan

  • jwajwa Posts: 4Questions: 2Answers: 0

    Thanks, I'll catch the error then.

This discussion has been closed.