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
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
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
andinitEdit
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 theinitRemove
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 thaninitRemove
. This should do the job:It uses
modifier()
androws().data()
to get the data for the rows to be removed, since that is not information that is passed intoopen
.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 yourinitRemove
to continue working. That method will work for thetitle
in the current release.Allan
Hi Allan,
Thanks for the workaround. This will certainly work for the time being. I had to use
editor.mode() === 'remove'
instead oftype === 'remove'
for mode detection since type is one ofmain
,inline
orbubble
. Other than that it works great!Thanks again for your help!
Doh of course it is - thanks for pointing that out!
Regards,
Allan