Inline Editor Select2 Type Problem

Inline Editor Select2 Type Problem

ihuangmxihuangmx Posts: 26Questions: 9Answers: 1

when I use select2 type in inline editor, when i select and click the 'Enter' key, and submit not work , I only can use the Inline editing with a submit button mode

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    edited October 2018

    Editor (since 1.6) has a canReturnSubmit method that plug-ins can tell Editor if the return key will submit or not. You could add:

    canReturnSubmit: function () {
      return true;
    }
    

    to the plug-in to allow it to submit.

    Allan

  • ihuangmxihuangmx Posts: 26Questions: 9Answers: 1

    @allan

    I found that when I select a item, the focus is lose like that

    and the source code 5143 the value of el is the body element not the input element,so i click the 'Enter Key' , It doesn't work

    normally the focus should not lost and the el should be input element

  • ihuangmxihuangmx Posts: 26Questions: 9Answers: 1

    @allan the select2 type in create button or edit button also can't use 'enter' as a shortcut key to open or close dropdown list, I can only use mouse the open select2

    the select2 demo can do this by 'enter' key, and will not lose the input focus

  • ihuangmxihuangmx Posts: 26Questions: 9Answers: 1
    Answer ✓

    problem solved, the select2 4.0.3 can't focus the input when selecting a item, so the inline editor enter can't work, I use the 4.0.5 ,and it works, thank you

  • accenturecfaccenturecf Posts: 4Questions: 1Answers: 0

    Can you please provide us some code for understanding more?

  • Corado BarloccoCorado Barlocco Posts: 3Questions: 1Answers: 0

    There is an issue with inline editing and Select2: to submit values you must press enter after you've selected an option but pressing enter on a focused Select2 item, reopens it.
    At the moment (Select2 ver 4.10) i was able to solve the issue applying two changes (you must host the files though):

    FIRST

    On editor.select2.js, let canReturnSubmit return true; change

    canReturnSubmit: function() {
            return false;
        }
    

    to

    canReturnSubmit: function() {
            return true;
        }
    

    SECOND

    On select2.full.js, comment self.open on keypress for KEYS.ENTER, change

    this.on('keypress', function (evt) {
          var key = evt.which;
    
          if (self.isOpen()) {
            if (key === KEYS.ESC || key === KEYS.TAB ||
                (key === KEYS.UP && evt.altKey)) {
              ...
              ...
              ...
            }
          } else {
            if (key === KEYS.ENTER || key === KEYS.SPACE ||
                (key === KEYS.DOWN && evt.altKey)) {
              self.open();
    
              evt.preventDefault();
            }
          }
        });
    

    to

    this.on('keypress', function (evt) {
          var key = evt.which;
    
          if (self.isOpen()) {
            if (key === KEYS.ESC || key === KEYS.TAB ||
                (key === KEYS.UP && evt.altKey)) {
              ...
              ...
              ...
            }
          } else {
            if (key === KEYS.ENTER || key === KEYS.SPACE ||
                (key === KEYS.DOWN && evt.altKey)) {
              //self.open();
    
              evt.preventDefault();
            }
          }
        });
    
This discussion has been closed.