Editor 1.6.1: ajax.remove.success issue

Editor 1.6.1: ajax.remove.success issue

BROB201BROB201 Posts: 28Questions: 4Answers: 0

I am getting the following error:

TypeError: opts.success is undefined

I can't link to the page because it is on a private network, but I am providing the following data to the editor:

remove: {
    type: 'DELETE',
    url: '/api/updateIpSheetRow',
    data: function (data) {
        //some data code
    },
    success: function () {
        console.log('test');
    }
}

in the Editor.prototype._ajax function, it creates an opts object without initializing a success property and then tries to call

if ( optsCopy.success ) {
    opts.success.push( optsCopy.success );
    delete optsCopy.success;
}

The documentation does not provide an example of using the success callback, but does reference the jquery ajax function, and says that starting in version1.6, the success callback can be used.

Next I will try updating my library to 1.6.2 (I haven't looked at the code, but didn't see this in the release notes), but I wanted to let you know about this, and ask if you had any immediate solutions.

This question has an accepted answers - jump to answer

Answers

  • BROB201BROB201 Posts: 28Questions: 4Answers: 0
    edited May 2017

    It does appear that the issue would still exist in 1.6.2, since opts.success.push is being called still.

  • BROB201BROB201 Posts: 28Questions: 4Answers: 0

    I fixed it by adding success: [] to the opts object.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    Thanks for letting me know about this and also digging into the issue. I agree - this is still an issue present in 1.6.2. I'm going to finalise the changes for 1.6.3 shortly and will have the release available this week. This change will be included.

    Regards,
    Allan

  • BROB201BROB201 Posts: 28Questions: 4Answers: 0
    edited May 2017

    edit: making a new question out of the following

    This is off the original topic, but the purpose for using this callback was to remove one or more additional rows which are linked to the removed row. If I remove the additional row in the preRemove or the success callback, some sort of state is preventing the actual removed row from being removed - as if it sees that a row was already removed, and stops. If I try to remove the additional rows in the postRemove event, then the data on the primary removed row which links to the secondary is already gone, so I can't find the linked secondary row. Is there a specific event intended for this purpose, or something on the editor I can modify to restore the state?

            //preRemove happens after the ajax call but before the row and data() is removed
    
            //response contains the primary keys of the removed rows, passed on from the
            //remove request
            editor.on('preRemove', function (e, response) {
                $.each(response.data, function (index, ipskey) {
                    var datatable = table.DataTable();
                    var rowData = datatable.row('#' + ipskey).data();
                    if (rowData.labelkey === 2) {
                        var fromRow = datatable.row('#' + rowData.changed_fields.ipskey.original);
                        //by delaying it by a second, both rows are removed. otherwise the row
                        //removed with the editor isn't actually removed
                        setTimeout(function () {fromRow.remove().draw();}, 1000);
                    }
                });
            });
    
  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    I think the new question (correct me if I am wrong) overlaps with this one. Let's keep that discussion in the new thread.

    Allan

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Just to confirm, the success issue fix has been committed and will be in 1.6.3.

    Allan

This discussion has been closed.