kevinongko / vue-numeric

Input field component to display a formatted currency value based on Vue.js
https://kevinongko.github.io/vue-numeric/
MIT License
461 stars 118 forks source link

[Feature request] Clear input on focus when value is zero #26

Closed ankurk91 closed 7 years ago

ankurk91 commented 7 years ago

Hi,

When current value is zero 0.00 and user focus on input, user has to remove this value by pressing backspace 4 times and then he can start typing new values. It would be good if component can clear the input field automatically when value is zero.

I made a simple directive to achieve this.

Vue.directive('clear-zero', {
  bind: function (el, binding, vnode) {
    el.onfocus = function () {
      if (parseFloat(el.value) === 0) {
        console.log('Clear value');
        el.value = null;
      }
    };
  }
});
<vue-numeric v-clear-zero currency="$" :precision="2" v-model="amount ></vue-numeric>

Current behavior vue-numeric-issue Expected behavior (with directive) directive

kevinongko commented 7 years ago

Thanks, this behavior is fixed in v2.0.0