Uncaught TypeError: editor.field is not a function

Uncaught TypeError: editor.field is not a function

Lennart OesterLennart Oester Posts: 12Questions: 2Answers: 1

I have tried for almost 10 hours straight and cannot find the answer.
Everything is working except where I want to change data in the a Dropfown based on a selection in another dropdown
When I create og Edit data

This single line of code is the reason to my frystrations
editor.field('projects_rss.feed_category_id').update(obj);

this is my client side code

var editor;

$(document).ready(function() {


    editor = new $.fn.dataTable.Editor( {
        ajax: "content_projects_rss.view.php",
        table: "#tbl",
        fields: [ {
                label: "User Id",
                name: "projects.user_id",
                def: function () { return <?php echo $_SESSION['id']?> },
                type: "hidden",
            }, 
            { label: "Project", name: "projects_rss.project_id", type: 'select' },
            { 
                label: "Feed", 
                name: "projects_rss.feed_id", 
                type: 'select' 
            },
            { label: "Feed Category", name: "projects_rss.feed_category_id", type: 'select' },
            {label: 'Repeat:',
            name: 'projects_rss.repeating',
            type: 'select',
            options: [
                { label: 'No Repeat', value: '0' },
                { label: 'Every 24 hours', value: '24' },
                { label: 'Every 12 hours', value: '12' },
                { label: 'Every 6 hours', value: '6' },
                { label: 'Every 3 hours', value: '3' },
                { label: 'Every 1 hour', value: '1' },
            ]},
            {label: 'Number of Articles:',
            name: 'projects_rss.articles',
            type: 'select',
            options: [
                { label: '1 Article', value: '1' },
                { label: '2 Articles', value: '2' },
                { label: '3 Articles', value: '3' },
                { label: '4 Articles', value: '4' },
                { label: '5 Articles', value: '5' },
                { label: '6 Articles', value: '6' },
                { label: '7 Articles', value: '7' },
                { label: '8 Articles', value: '8' },
                { label: '9 Articles', value: '9' },
                { label: '10 Articles', value: '10' },
                { label: '20 Articles', value: '20' },
                { label: '30 Articles', value: '30' },
            ]},
            {label: 'Publish:',
            name: 'projects_rss.publish',
            type: 'select',
            options: [
                { label: 'Publish', value: '1' },
                { label: 'Draft', value: '0' },
            ]}


        ]

    });

    editor.dependent( 'projects_rss.feed_id', function ( val, data, callback ) {
        //load_list(val); //Function to load Select List
        $.ajax({
            type: "POSt",
            url: 'content_projects_rss.ajax.php',
            data: { id: val}, 
            success:function(data) {
                e = $.parseJSON(data);  //make PHP JSON TO JQUERY OBJECT
                    var obj = new Object;
                    $.each(e,function(key, value)  //GET EACH OBJECT
                    {
                        obj[value.job] = value.id;
                    });
                    editor.field('projects_rss.feed_category_id').update(obj);     //Update Select List
                }
            }

        )
    });

    function load_list(val){

        $.ajax({
            type: "GET",
            url: 'content_projects_rss.ajax.php',
            data: { id: val}, 
            success:function(data) {
                e = $.parseJSON(data);  //make PHP JSON TO JQUERY OBJECT
                    var obj = new Object;
                    $.each(e,function(key, value)  //GET EACH OBJECT
                    {
                        obj[value.job] = value.id;
                    });
                    editor.field('projects_rss.feed_category_id').update(obj);     //Update Select List
                }
            }

        )
    };


    datatable  = $('#tbl').DataTable( {
        dom: "Bfrtip",
        processing: true,
        serverSide: true,
        pageLength: 50,
        ordering: true,
        filter: true,
        deferRender: true,
        searching: true,
        ajax: {
            url: "content_projects_rss.view.php",
            type: 'POST',
            data: {
                },

            beforeSend : function (data) {
            },
            complete: function (data) {
                try{

                }
                finally{
                }
            },
        },
        columns: [
            { data: "projects.id" },
            { data: "projects.user_id" },
            { data: "projects.name" },
            { data: "rss_feeds.name" },
            { data: "rss_data_categories.name" },
            { data: "projects_rss.repeating" },
            { data: "projects_rss.articles" },
            { data: "projects_rss.publish" },
            ],
        columnDefs: [
            { "visible": false, "targets": 0 },
            { "visible": false, "targets": 1 },
            { "visible": true, "targets": 2 },
            { "visible": true, "targets": 3 },
            { "visible": true, "targets": 4 },
            { "visible": true, "targets": 5,
                render: function (data, type, row) {
                    switch (data) {
                        case 0: return 'No repeat';break;
                        case 1: return 'Every 1 hour';break;
                        case 3: return 'Every 3 hours';break;
                        case 6: return 'Every 6 hours';break;
                        case 12: return 'Every 12 hours';break;
                        case 24: return 'Every 24 hours';break;
                    }
                }
            },
            { "visible": true, "targets": 6 ,
                render: function (data, type, row) {
                    switch (data) {
                        case 1: return '1 Article';break;
                        case 2: return '2 Articles';break;
                        case 3: return '3 Articles';break;
                        case 4: return '4 Articles';break;
                        case 5: return '5 Articles';break;
                        case 6: return '6 Articles';break;
                        case 7: return '7 Articles';break;
                        case 8: return '8 Articles';break;
                        case 9: return '9 Articles';break;
                        case 10: return '10 Articlea';break;
                        case 20: return '20 Articlea';break;
                        case 30: return '30 Articlea';break;
                    }
                }
            },
            { "visible": true, "targets": 7,
                render: function (data, type, row) {
                    switch (data) {
                        case 0: return 'Draft';break;
                        case 1: return 'Publish';break;
                    }
                }
             },
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit", editor: editor },
            {
                extend: "remove",
                editor: editor,
                formMessage: function ( e, dt ) {
                    var rows = dt.rows( e.modifier() ).data().pluck('first_name');
                    return 'WARNING: Do you wish to delete this Project setting. It cannot be undone';
                }
            }
        ]
    } );
} );

This question has an accepted answers - jump to answer

Answers

  • Lennart OesterLennart Oester Posts: 12Questions: 2Answers: 1
    Answer ✓

    I found the error.
    Another editor variable was delclared

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Thanks for the update! That would do it :).

    Glad to hear you resolve the issue,
    Allan

Sign In or Register to comment.