vue-touch-keyboard icon indicating copy to clipboard operation
vue-touch-keyboard copied to clipboard

useKbEvents doesn't trigger v-model update

Open SteveJay7 opened this issue 8 years ago • 5 comments

I have set the options.useKbEvents to true and I hoped that this will trigger an update of the data property I used in v-model with the input field. I see that the keypress event is dispatched but the data property doesn't update. Do you know why? Is there a workaround to achieve an automatic update of the data property?

Thanks for your help!

SteveJay7 avatar Jul 21 '17 15:07 SteveJay7

My solution was to create a :change trigger, and in that trigger, tell the input to fire an input event:

  this.$refs.keyboard.input.dispatchEvent(new Event('input', { bubbles: true }));

microfauna avatar Jul 31 '17 11:07 microfauna

v-model not work with this keyboard

FedorovP777 avatar Aug 01 '17 13:08 FedorovP777

the solution proposed by @nicksahler just works - thank you! i am using it like this (not with $refs):

<vue-touch-keyboard v-if="keyboard.visible" :layout="keyboard.layout" :input="keyboard.input" :change="manualDispatch"/>

methods: {
  manualDispatch () {
    this.keyboard.input.dispatchEvent(new Event('input', { bubbles: true }));
  }
}

mfandl avatar Sep 29 '17 13:09 mfandl

Another example with different var names using @nicksahler solution and working

<vue-touch-keyboard v-if="kbVisible"
                          :layout="kbLayout"
                          :cancel="kbHide"
                          :accept="kbAccept"
                          :input="kbInput"
                          :change="manualDispatch"/>

kbShow(e) {
        this.kbInput = e.target;
        this.kbLayout = e.target.dataset.layout;

        if (!this.kbVisible)
          this.kbVisible = true;
      }

 manualDispatch () {
        this.kbInput.dispatchEvent(new Event('input', { bubbles: true }));
      }

thanks

jonezineworks avatar Mar 15 '18 12:03 jonezineworks

Should someone submit a pull request for this or should this be left for manual implementation? I had to do the same thing, regardless of the useKbEvents value.

adrum avatar Jun 08 '18 01:06 adrum