Dialog title and message are being overwritten after being set in init* event

Dialog title and message are being overwritten after being set in init* event

cbtdevcbtdev Posts: 39Questions: 12Answers: 0

Hello, I recently updated my Editor code base from 1.4.0 to 1.4.2 and have noticed the init* events no longer work for setting the title/message of the dialog. Here is a snippet of my code as it was written in 1.4.0:

editor
.on( 'initRemove', function( e, node, data ) {
        var plural = data.length > 1 ? 's?' : '?';
        editor.title('Delete ' + data.length + ' Ticket' + plural);
        var message = 'Are you sure you wish to delete the following selected ticket' + plural + ' This action cannot be undone.<br/><br/>';
        $.each(data, function(index, value) {
            message += value.ticketNumber + ' (' + value.lastName + ')<br/>';
        });
        editor.message(message);
    }

In following the sequence of events it seems that the new values have been overwritten by the time the next event (preOpen) is called. I've looked through the release notes and didn't see anything directly relating to this issue.

Any help would be greatly appreciated.

Thank you!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi,

    Thanks for raising this issue - this was an unintentional (and at the time unknown) consequence of another bug fix. It should effect the initRemove event only - initCreate and initEdit are unaffected.

    In 1.4.1- there could be a timing error which meant that a message defined by the TableTools buttons would not be displayed - to resolve I updated the buttons to use the second form of remove() whereby the message is passed into the second parameter for the method. The result is that the message is set after the initRemove event (the create and edit buttons don't set a message themselves which is why they are unaffected).

    The same applies to the title (although the create and edit actions will also have a problem there as well).

    At the moment, the way to fix this is to use the open event, rather than initRemove. This should do the job:

    editor
    .on( 'open', function( e, type ) {
        if ( type === 'remove' ) {
            var data = table.rows( this.modifier() ).data();
            var plural = data.length > 1 ? 's?' : '?';
            editor.title('Delete ' + data.length + ' Ticket' + plural);
            var message = 'Are you sure you wish to delete the following selected ticket' + plural + ' This action cannot be undone.<br/><br/>';
            $.each(data, function(index, value) {
                message += value.ticketNumber + ' (' + value.lastName + ')<br/>';
            });
            editor.message(message);
        }
    } )
    

    It uses modifier() and rows().data() to get the data for the rows to be removed, since that is not information that is passed into open.

    Longer term, I will add the ability for the message set by the remove button to be provided as a function so it can dynamically define the question based on the data available.

    The other option, which unfortunately won't work in the current Editor release, although I would be happy to provide you with the patch if you like, would be to set the message that the button uses to null. That would stop it from writing a message to the display and thus allow your initRemove to continue working. That method will work for the title in the current release.

    Allan

  • cbtdevcbtdev Posts: 39Questions: 12Answers: 0

    Hi Allan,

    Thanks for the workaround. This will certainly work for the time being. I had to use editor.mode() === 'remove' instead of type === 'remove' for mode detection since type is one of main, inline or bubble. Other than that it works great!

    Thanks again for your help!

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Doh of course it is - thanks for pointing that out!

    Regards,
    Allan

This discussion has been closed.