probil / v-mask

🔡 Tiny input mask library for Vue.js (directive)
https://v-mask-demo.netlify.com
MIT License
902 stars 132 forks source link

Prevent field clean when changing mask #576

Open cesartagplus opened 1 year ago

cesartagplus commented 1 year ago

Hi!

I have a dynamic mask, and when the mask changes (based on another inputs) it cleans the field. I want to prevent this, and clean the field only if the test fails. Is there a way ?

the code looks like this:

          <el-input
            v-model="test"
            v-mask="customMask"
          />
watch: {
 inputC: {
      immediate: true,
      handler () {
        this.customMask = this.changeMask(inputA, inputB)
      }
    }
}
methods: {
changeMask = (inputA, inputB) => {

  let actualMask = []

  if (inputA) {
    actualMask = [/1/, '.', /\d/, /\d/, /\d/]
  }

  if (inputB) {
    actualMask = [/2/, '.', /\d/, /\d/, /\d/]
  }

  return actualMask
}
}