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 { ...@@ -39,9 +39,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,
...@@ -70,32 +69,36 @@ export default { ...@@ -70,32 +69,36 @@ export default {
methods: { methods: {
initMask() { initMask() {
try { try {
this.maskCore = new InputMask({ if (this.mask instanceof Object) {
pattern: this.mask, this.maskСore = new InputMask(this.mask)
value: '', } else {
placeholderChar: this.placeholderChar, this.maskCore = new InputMask({
/* eslint-disable quote-props */ pattern: this.mask,
formatCharacters: { value: '',
'a': { placeholderChar: this.placeholderChar,
validate: char => /^[A-Za-zА-Яа-я]$/.test(char), /* eslint-disable quote-props */
}, 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: () => true, transform: char => char.toUpperCase(),
},
'+': {
validate: () => true,
},
}, },
}, /* eslint-enable */
/* eslint-enable */ });
}); }
[...this.$refs.input.value].reduce((memo, item) => this.maskCore.input(item), null); [...this.$refs.input.value].reduce((memo, item) => this.maskCore.input(item), null);
this.maskCore.setSelection({ this.maskCore.setSelection({
start: 0, 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