Commit af38d151 authored by niksmr's avatar niksmr Committed by GitHub

Merge pull request #15 from dmitrichev/feature/mask-as-object

Added the ability to specify an object as a mask
parents 61211263 9fe4fa3c
......@@ -39,9 +39,8 @@ export default {
type: String,
},
mask: {
type: String,
required: true,
validator: value => !!(value && value.length >= 1),
validator: value => !! ((value && value.length >= 1) || value instanceof Object)
},
placeholderChar: {
type: String,
......@@ -70,32 +69,36 @@ export default {
methods: {
initMask() {
try {
this.maskCore = new InputMask({
pattern: this.mask,
value: '',
placeholderChar: this.placeholderChar,
/* eslint-disable quote-props */
formatCharacters: {
'a': {
validate: char => /^[A-Za-zА-Яа-я]$/.test(char),
},
'A': {
validate: char => /^[A-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: () => true,
if (this.mask instanceof Object) {
this.maskСore = new InputMask(this.mask)
} else {
this.maskCore = new InputMask({
pattern: this.mask,
value: '',
placeholderChar: this.placeholderChar,
/* eslint-disable quote-props */
formatCharacters: {
'a': {
validate: char => /^[A-Za-zА-Яа-я]$/.test(char),
},
'A': {
validate: char => /^[A-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: () => true,
},
},
},
/* eslint-enable */
});
/* eslint-enable */
});
}
[...this.$refs.input.value].reduce((memo, item) => this.maskCore.input(item), null);
this.maskCore.setSelection({
start: 0,
......
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