Commit 1056f6d3 authored by vagrant's avatar vagrant

Added the ability to specify an object as a mask

parent c387e294
...@@ -35,9 +35,8 @@ export default { ...@@ -35,9 +35,8 @@ export default {
type: String type: String
}, },
mask: { mask: {
type: String,
required: true, required: true,
validator: value => !! (value && value.length >= 1) validator: value => !! ((value && value.length >= 1) || value instanceof Object)
}, },
placeholderChar: { placeholderChar: {
type: String, type: String,
...@@ -67,30 +66,34 @@ export default { ...@@ -67,30 +66,34 @@ export default {
initMask() { initMask() {
try { try {
this.mask_core = new InputMask({ if (this.mask instanceof Object) {
pattern: this.mask, this.mask_core = new InputMask(this.mask)
value: '', } else {
placeholderChar: this.placeholderChar, this.mask_core = new InputMask({
formatCharacters: { pattern: this.mask,
'a': { value: '',
validate: char => /^[A-Za-zА-Яа-я]$/.test(char), placeholderChar: this.placeholderChar,
}, formatCharacters: {
'A': { 'a': {
validate: char => /^[A-Za-zА-Яа-я]$/.test(char) , validate: char => /^[A-Za-zА-Яа-я]$/.test(char),
transform: char => char.toUpperCase() },
}, 'A': {
'*': { validate: char => /^[A-Za-zА-Яа-я]$/.test(char),
validate: char => /^[\dA-Za-zА-Яа-я]$/.test(char), transform: char => char.toUpperCase()
}, },
'#': { '*': {
validate: char => /^[\dA-Za-zА-Яа-я]$/.test(char), validate: char => /^[\dA-Za-zА-Яа-я]$/.test(char),
transform: char => char.toUpperCase() },
}, '#': {
'+': { validate: char => /^[\dA-Za-zА-Яа-я]$/.test(char),
validate: char => true, transform: char => char.toUpperCase()
}, },
} '+': {
}) validate: char => true,
},
}
})
}
for (let i = 0; i < this.$refs.input.value.length; ++i) { for (let i = 0; i < this.$refs.input.value.length; ++i) {
this.mask_core.input(this.$refs.input.value[i]) this.mask_core.input(this.$refs.input.value[i])
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment