Possible for "onReturn" to execute a function?

Possible for "onReturn" to execute a function?

hhsiaohhsiao Posts: 12Questions: 4Answers: 0

Hello Alan,

Want to know if it is possible for "onReturn" to execute a function instead of just plain "submit"?

Regards,

Henry

This question has an accepted answers - jump to answer

Answers

  • hhsiaohhsiao Posts: 12Questions: 4Answers: 0

    So I just added this support, for anyone interested
    find following

    if ( that.s.displayed && opts.onReturn === 'submit' && e.keyCode === 13 && returnFriendlyNode ) { // return
        e.preventDefault();
        that.submit();
    }
    

    and add following immediately after it

    else if (that.s.displayed && typeof opts.onReturn === 'function' && e.keyCode === 13  && returnFriendlyNode ) { // return)
        e.preventDefault();
        opts.onReturn();
    }
    
  • allanallan Posts: 63,834Questions: 1Answers: 10,518 Site admin
    Answer ✓

    Hi Henry,

    Currently no - there isn't an option for that, but its a really good suggestion for a future enhancement. Can I ask what the use case is? I presume you want to do some kind of logic to decide if it should be submitted or not?

    Allan

  • hhsiaohhsiao Posts: 12Questions: 4Answers: 0

    Hi Alan,

    Yes indeed I have need to manipulate data before data is sent off. What happen is I wrote a custom buttons call "Update" and then I realize when I hit "Enter" it's just executing "editor.submit()".

    Henry

  • allanallan Posts: 63,834Questions: 1Answers: 10,518 Site admin

    I have need to manipulate data before data is sent off

    preSubmit can be used for that.

    However, I like this idea a lot - I've added it to the feature list for Editor 1.6.

    Thanks for the suggestion!

    Regards,
    Allan

  • allanallan Posts: 63,834Questions: 1Answers: 10,518 Site admin

    Just in case anyone else finds this discussion while browsing. Editor 1.6 will indeed have the ability to define onReturn (and the other on* options) as a function.

    For the use case above preSubmit is still the way to go, but the new ability provides other options.

    Allan

  • johnsonjjohnsonj Posts: 14Questions: 3Answers: 0

    I stumbled across this thread today. How is onReturn supposed to work with functions? I have tried:

      editor.inline(this, {
                    onBlur: 'submit',
                    //focus on field where error occurred
                    onFieldError: 'focus',
                    onReturn: test(this)
                    
                }
    

    and

     editor.inline(this, {
                    onBlur: 'submit',
                    //focus on field where error occurred
                    onFieldError: 'focus',
                    onReturn: function(){
    
                        PressedReturn = true;
                }
    

    The first one calls my test function every time I click on the table cell I wish to edit. The second doesn't do anything at all. An example would be great. I made sure to download and "install" v1.6.1 before trying this.

  • johnsonjjohnsonj Posts: 14Questions: 3Answers: 0

    Never mind. I was missing submit().. Got it working! Great addition! Final code:

     editor.inline(this, {
                    onBlur: 'submit',
                    //focus on field where error occurred
                    onFieldError: 'focus',
                    onReturn: function (e) {
                        PressedReturn = true;
                        e.submit();
                    }
    
  • allanallan Posts: 63,834Questions: 1Answers: 10,518 Site admin

    Perfect. Good to hear you got it working.

    Allan

This discussion has been closed.