Esc is not exiting from inline editor
Esc is not exiting from inline editor
I am just getting started with datatables.editor and it works perfectly EXCEPT for escape. I have tried not changing the default (which should be onEsc: 'close'), and I have tried explicitly setting it:
formOptions: {
inline: {
onEsc: 'close'
}
}
Yet when I press esc key (on a mac) nothing happens, and in fact the input gets stuck, and I cannot create another editor input on any other cell.
Suggestions? Is it a different key on the mac?
thanks
This question has an accepted answers - jump to answer
Answers
for the record, when I load the inline editing example it works fine. I'm wondering if something else is grabbing the escape.
Yep. I have confirmed that because I include a custom field editor which is a bootstrap-tagsinput editor, that is clobbering the escape functionality.
Ok now I am discovering that my custom tagsinput plugin is being called even when the type of the field is text. This custom plugin overrides the preClose and is returning false. I will look into why this plugin is called.
I've adapted my code and gotten to a point where if I press escape twice it closes; I have changed my plugin to just do 'one' for preClose, and added that one every time there is a set ...
set: function ( field, val ) {
this.closeable = false;
this.one('preClose', function( e ){
return this.closeable;
});
but I still do not understand why this set method for my plugin is called when the text input is created.
To clarify, this is all for inline editing.
Is the plug-in handling the esc key at all (i.e. is there an event listener for it)?
Given that the problem doesn't appear to be in Editor itself, can you give me a link to a page that shows the issue so it could be debugged.
Allan
I will set up a jsfiddle for it. The issue is that the plug-in has to override the preClose so that the user can press return after selecting a tag. My confusion is why the plug-in "set' is called even when it is not the inline editor being displayed. I have also tried changing my editor such that the inline method is connected separately for the different types of inputs, but since it's all using the same editor the problem persists.
The whole form is prepped which even a single field is inline edited as one field's value can effect another's - therefore they need to gain the values from the target row.
Allan
Is there a different event I can listen to to get a callback only when my plug-in gets focus?
I have found this which is giving me the field that I am truly editing:
_this.on('preOpen', function( e, node, data ){
var theField = e.currentTarget.s.includeFields[0]
if (theField == 'tags'){
_this.closeable = false;
} else {
_this.closeable = true;
}
});
You can use the
displayed()
method to get the displayed fields rather than needing to use the private API. I would suggest you never use thes
object from Editor - it is private. It can, will and does change between versions.Allan
Perfect, even better. My code is now:
...
...
thanks for your help!