Esc is not exiting from inline editor

Esc is not exiting from inline editor

tamarmottamarmot Posts: 14Questions: 3Answers: 0

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

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    for the record, when I load the inline editing example it works fine. I'm wondering if something else is grabbing the escape.

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    Yep. I have confirmed that because I include a custom field editor which is a bootstrap-tagsinput editor, that is clobbering the escape functionality.

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    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.

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    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.

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    To clarify, this is all for inline editing.

  • allanallan Posts: 63,259Questions: 1Answers: 10,421 Site admin

    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

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    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.

  • allanallan Posts: 63,259Questions: 1Answers: 10,421 Site admin

    My confusion is why the plug-in "set' is called even when it is not the inline editor being displayed

    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

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    Is there a different event I can listen to to get a callback only when my plug-in gets focus?

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0

    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;
    }
    });

  • allanallan Posts: 63,259Questions: 1Answers: 10,421 Site admin
    Answer ✓

    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 the s object from Editor - it is private. It can, will and does change between versions.

    Allan

  • tamarmottamarmot Posts: 14Questions: 3Answers: 0
    edited April 2016

    Perfect, even better. My code is now:

    ...

      _this.on('postSubmit', function( e, data, action ){
            if (_this.displayed()[0] === 'tags'){
                _this.closeable = true;
            }
        });
    
        _this.on('open', function( e, node, data ){
            if (_this.displayed()[0] === 'tags'){
                _this.closeable = false;
            }
        });
    
        _this.on('preClose', function( e ){
            if (_this.displayed()[0] === 'tags'){
                return _this.closeable;
            } else {
                return true;
            }
        });
    

    ...

    thanks for your help!

This discussion has been closed.