0

In my <vue-numeric>

<vue-numeric
      currency="RMB"
      separator=","
      v-bind:minus="false"
      v-model="amount"
      v-bind:precision="2"
      class="form-control form-control-lg bg-secondary border-0 text-white"
    ></vue-numeric>

By using this code it can convert the user input to number type even the input contains string inside, but what I want is user only can insert numberand when alphabet pressed, it will display nothing

0

2 Answers 2

1

You could try adding a keydown event listener and test the keycode to see if it's a number:

@keydown="testNumber"

methods: {
  testNumber({ keyCode }) {
    if(keyCode < 48 || keyCode > 57) {
      event.preventDefault()
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

What you can do is extend/ overwrite the component options - e.g.:

import VueNumeric from "vue-numeric";
const inputHanlder = VueNumeric.methods["onInputHandler"];
VueNumeric.methods["onInputHandler"] = function(val) {
  // here the sanitizer
  this.amount = this.amountNumber;
  inputHanlder.bind(this)();
};
VueNumeric.watch["valueNumber"] = function(newValue) {
  console.log(newValue);
  if (this.$refs.numeric !== document.activeElement) {
    this.amount = this.format(newValue);
  } else {
    this.amount = newValue;
  }
};
export default VueNumeric;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.