Notice: Undefined index: data in Editor.php on line 1225

Notice: Undefined index: data in Editor.php on line 1225

wouterwouter Posts: 22Questions: 7Answers: 0

He everyone!

I'm trying to create something comparable to the "Standalone collection editor" in your Editor examples. I added a delete button to delete a panel, but php returns:

Notice: Undefined index: data in .../Editor.php on line 1225

Warning: Invalid argument supplied for foreach() in .../Editor.php on line 1225
{"data":[]}

So my guess was there's something wrong with the row_id, but the generated html looks pretty solid:

<div class="panel" data-editor-id="row_1">
<i class="remove fa fa-times" data-id="row_1"></i>
<span data-editor-field="data.name">hallo</span>
</div>

Anyone knows what this could be, or where i could start investigating?

For the full reference here's a simplified version of my js:

var editor;

    function createPanel ( data ){
        var id = data.DT_RowId;
        $( '<div class="panel" data-editor-id="'+id+'">'+
                '<i class="remove fa fa-times" data-id="'+id+'"/>'+
                '<span data-editor-field="data.name">'+data.name+'</span> '+
            '</div>'
            ).appendTo( '#panels' );
        }

    $(document).ready(function() {
            editor = new $.fn.dataTable.Editor( {
            ajax    :       '/pages/contacts/data.contacts.php',
            fields: [
                {
                    label: "name",
                    name: "name"
                    }
                ]
            });

        // Remove
        $('#panels').on( 'click', 'i.remove', function () {
            editor
                .title('Delete record')
                .buttons('Delete')
                .message('Are you sure you wish to delete this record?')
                .remove( $(this).data('id') );
            });

        $.ajax( {
            url: '/pages/contacts/data.contacts.php',
            dataType: 'json',
            success: function ( json ) {
                for ( var i=0, ien=json.data.length ; i<ien ; i++ ) {
                    createPanel( json.data[i] );
                    }
                }
            });
        });

and my php:

Editor::inst( $db, 'contacts', 'id' )
    ->fields(
        Field::inst( 'name' )
        )

    // ----------------------------------------------------------------
    ->process( $_POST )
    ->json();

Replies

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    First thing I would do is have a look at the data being sent to the server in the Network Inspector of your browser. What is being sent? Is there a data property?

    Allan

  • wouterwouter Posts: 22Questions: 7Answers: 0
    edited May 2019

    Thanks Alan!!! No you are right. I think its a scope issue. i changed:

        $('#panels').on( 'click', 'i.remove', function () {
                editor
                    .title('Delete record')
                    .buttons('Delete')
                    .message('Are you sure you wish to delete this record?')
                    .remove( $(this).data('id') );
                });
    

    into

            $('#panels').on( 'click', 'i.remove', function () {
                var id = $(this).data('id');
                editor
                    .title('Delete record')
                    .buttons('Delete')
                    .message('Are you sure you wish to delete this record?')
                    .remove( id );
                });
    

    an now it works!!

This discussion has been closed.