awesome-mask
Advanced tools
Comparing version 0.3.5 to 0.3.6
19
index.js
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _vue = require('vue'); | ||
var _vue2 = _interopRequireDefault(_vue); | ||
var _isCharacterKeypress = require('./is-character-keypress'); | ||
@@ -35,2 +39,11 @@ | ||
var applyMaskToDefault = function applyMaskToDefault(el, mask) { | ||
var isInputText = el instanceof HTMLInputElement; | ||
var inputText = el; | ||
if (!isInputText) { | ||
inputText = el.querySelector('input'); | ||
} | ||
inputText.value = mask && mask.length > 0 ? _vanillaMasker2.default.toPattern(inputText.value, mask) : inputText.value; | ||
}; | ||
exports.default = { | ||
@@ -40,5 +53,11 @@ bind: function bind(el, binding) { | ||
el.dataset.mask = binding.value; | ||
applyMaskToDefault(el, binding.value); | ||
el.setAttribute('maxlength', el.dataset.mask.length); | ||
el.addEventListener('keydown', inputHandler); | ||
}, | ||
update: function update(el, binding) { | ||
// this is only for v-model | ||
if (binding.value.length < 1) return; | ||
applyMaskToDefault(el, binding.value); | ||
}, | ||
unbind: function unbind(el, binding) { | ||
@@ -45,0 +64,0 @@ if (binding.value.length < 1) return; |
{ | ||
"name": "awesome-mask", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"description": "An awesome mask directive for Vue.js using vanilla-masker from `https://github.com/BankFacil/vanilla-masker`", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -45,27 +45,18 @@ The awesome-mask runs with `Vue.js` and uses the `vanilla-masker` to make your form awesome with masks. | ||
You can also change the mask on the fly: | ||
Sample using import: | ||
```vue | ||
<template> | ||
<p> | ||
<input v-mask="mask" type="text" @input="updateMask"> | ||
</p> | ||
</template> | ||
import Component from './components/Component' | ||
import AwesomeMask from 'awesome-mask' | ||
<script> | ||
export default { | ||
data() { | ||
return { | ||
mask: '999.999.999-99' | ||
} | ||
name: 'app', | ||
components: { | ||
Component | ||
}, | ||
methods: { | ||
updateMask (val) { | ||
if(val.lenght > 14){ | ||
this.mask = '99.999.999/9999-99' | ||
} | ||
} | ||
directives: { | ||
'mask': AwesomeMask | ||
} | ||
} | ||
</script> | ||
``` | ||
DISCLAIMER: If you use Windows, please use the version `0.3.3`, there was a problem with Vanilla-Masker to build at Windows. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5652
75
62