vue-the-mask icon indicating copy to clipboard operation
vue-the-mask copied to clipboard

Input @blur.native not reset the value properly

Open Bigdragon13th opened this issue 5 years ago • 2 comments

Scenario: I need a number input that will reset its value back to min value if the value in the field is lower than min value only after it's blur.

Current Behavior: Given this snippet:

<template>
  <div>
    <TheMask
      :mask="['####']"
      v-model="count"
      @blur.native="resetCount"
    />
    <div>{{ count }}</div>
  </div>
</template>

<script>
import { TheMask } from 'vue-the-mask';

export default {
  components: {
    TheMask,
  },

  data() {
    return {
      count: 1,
      minCount: 1,
    };
  },

  methods: {
    resetCount() {
      if (this.count < this.minCount) {
        this.count = this.minCount;
      }
    },
  },
};
</script>

The count in mask input failed to update if:

  • Remove the value in input
  • Click somewhere outside
  • The value pop back to 1 since it's the min value // This one correct
  • Try remove the value again
  • Click somewhere outside again
  • The value is not pop back to 1 // Incorrect behavior

I tried debugging and found that lastValue in the component not updated properly when the value update via @blur from parent, this might be the cause of the issue.

Bigdragon13th avatar Jun 03 '19 09:06 Bigdragon13th

I've bumped into exact same issue.

@Bigdragon13th, did you manage to fix it?

kosmeln avatar Apr 09 '20 10:04 kosmeln

@kosmeln I can't remember this anymore, it's too long ago, lol. I think I created my own input for this at that time.

Bigdragon13th avatar Apr 11 '20 06:04 Bigdragon13th