vuejs-tips / vue-the-mask

Tiny (<2k gzipped) and dependency free mask input for Vue.js
https://vuejs-tips.github.io/vue-the-mask/
1.74k stars 213 forks source link

Email input type problem #87

Open antonioribeiro opened 6 years ago

antonioribeiro commented 6 years ago

If we do (I know I'll have to tweak to accept other chars!):

<div id="app">
  <input type="email" v-mask="['XXXXXXXXXXXXXXXXXXXXXXXXXXX']" />
</div>

We get a

vue-the-mask.js:1 Uncaught DOMException: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('email') does not support selection.
    at HTMLInputElement.e.oninput (https://unpkg.com/vue-the-mask@0.11.1/dist/vue-the-mask.js:1:1590)
e.oninput @ vue-the-mask.js:1

https://jsfiddle.net/xe7nd0o2/2/

n3ps commented 5 years ago

Getting this problem too

helderhernandez commented 4 years ago

Is this problem still unsolved?

brolnickij commented 4 years ago

:(

victor-duarte commented 2 years ago

A workaround is to avoid affecting the inputs of type email

.../src/plugins/mask.ts

import { defineNuxtPlugin } from '#app';
import { mask } from 'vue-the-mask';

export default defineNuxtPlugin((app) => {
  app.vueApp.directive('mask', {
    created: (el, binding, vnode, prevVnode) => {
      // Avoid setting directives on `inputs` of type `email` to avoid error
      // thrown by `vue-the-mask`.
      if (vnode.props.type === 'email') return;

      return mask(el, binding, vnode, prevVnode);
    },
  });
});