mydea / handsontable-chosen-editor

Use a chosen select field in a Handsontable.
http://mydea.github.io/handsontable-chosen-editor/
MIT License
63 stars 36 forks source link

focus problems #9

Open Lokomotom opened 6 years ago

Lokomotom commented 6 years ago

value: function focus() { // Add an empty space to texarea. It is necessary for safari to enable "copy" command from menu bar. this.mainElement.value = ' '; this.mainElement.select(); }

In version 4.0.0 they updated this function and it causes this TypeError: this.mainElement.select is not a function when you focus cell which is using this editor.

Any idea how to fix it please?

mydea commented 6 years ago

I am currently not really working on this, but I do accept PRs if you find time to figure this out!

Lokomotom commented 6 years ago

SOLVED! Here is new solution.

ChosenEditor.prototype.createElements = function () { this.$body = $(document.body);

      this.TEXTAREA = document.createElement('textarea');
      let select = document.createElement('select');
      this.TEXTAREA.appendChild(select);
      //this.TEXTAREA.setAttribute('type', 'text');
      this.$textarea = $(this.TEXTAREA.children[0]);

      Handsontable.dom.addClass(this.TEXTAREA.children[0], 'handsontableInput');

      this.textareaStyle = this.TEXTAREA.children[0].style;
      this.textareaStyle.width = 0;
      this.textareaStyle.height = 0;

      this.TEXTAREA_PARENT = document.createElement('DIV');
      Handsontable.dom.addClass(this.TEXTAREA_PARENT, 'handsontableInputHolder');

      this.textareaParentStyle = this.TEXTAREA_PARENT.style;
      this.textareaParentStyle.top = 0;
      this.textareaParentStyle.left = 0;
      this.textareaParentStyle.display = 'none';
      this.textareaParentStyle.width = "200px";

      this.TEXTAREA_PARENT.appendChild(this.TEXTAREA.children[0]);

      this.instance.rootElement.appendChild(this.TEXTAREA_PARENT);

      var that = this;
      this.instance._registerTimeout(setTimeout(function () {
          that.refreshDimensions();
      }, 0));
  };
dinhgiabao1993 commented 6 years ago

@element150 Thanks a lot! You made my day. Could you please add answer to handsontable issue too? I almost miss this solution if i don't open this repo issues =(