2
0
mirror of https://github.com/tenrok/maska.git synced 2026-06-20 20:00:34 +03:00

Added reactivity to vue mask

This commit is contained in:
Alexander Shabunevich
2020-02-01 17:00:03 +03:00
parent a969eb4942
commit d3a7c0eee9
4 changed files with 21 additions and 11 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+14
View File
@@ -29,6 +29,13 @@
</div> </div>
<p class="help is-family-code">v-maska="['+1 (###) ##-##-##', '+1 (###) ###-##-##']"</p> <p class="help is-family-code">v-maska="['+1 (###) ##-##-##', '+1 (###) ###-##-##']"</p>
</div> </div>
<div class="field">
<label class="label">Reactive mask: <input type="checkbox" v-model="dotFormat"> use dot as date separator?</label>
<div class="control">
<input v-maska="dateMask" class="input">
</div>
<p class="help is-family-code">v-maska="dateMask" — reactive mask by `dateMask` computed property</p>
</div>
<div class="field"> <div class="field">
<label class="label">Hex color (custom tokens): {{ color }}</label> <label class="label">Hex color (custom tokens): {{ color }}</label>
<div class="control"> <div class="control">
@@ -118,7 +125,14 @@
el: '#vue-form', el: '#vue-form',
data: { data: {
phone: '19992345678', phone: '19992345678',
dotFormat: false,
color: null color: null
},
computed: {
dateMask: function() {
return this.dotFormat ? '##.##.####' : '##/##/####'
}
} }
}); });
+5 -9
View File
@@ -15,15 +15,11 @@ function getOpts (mask) {
} }
function needUpdate (mask) { function needUpdate (mask) {
if (isString(mask.value) && isString(mask.oldValue) && mask.value === mask.oldValue) { return !(
return false (isString(mask.value) && mask.value === mask.oldValue) ||
} (Array.isArray(mask.value) && JSON.stringify(mask.value) === JSON.stringify(mask.oldValue)) ||
(mask.value && mask.value.mask && mask.oldValue && mask.oldValue.mask && mask.value.mask === mask.oldValue.mask)
if (mask.value && mask.oldValue && mask.value.mask === mask.oldValue.mask) { )
return false
}
return true
} }
export default function directive (el, mask) { export default function directive (el, mask) {
+1 -1
View File
@@ -27,7 +27,7 @@ export default class Maska {
init () { init () {
for (let i = 0; i < this._el.length; i++) { for (let i = 0; i < this._el.length; i++) {
const el = findInputElement(this._el[i]) const el = findInputElement(this._el[i])
if (!el.dataset.mask && this._opts.mask) { if ((!el.dataset.mask && this._opts.mask) || el.dataset.mask !== this._opts.mask) {
el.dataset.mask = this._opts.mask el.dataset.mask = this._opts.mask
} }
this.updateValue(el) this.updateValue(el)