I am using the following code for price entry with vue js, but it does not give the output I want. and I want to cancel from keyboard keys (POINT). only the comma will work. By the way, I'm new among you, I would be happy if you can help me accordingly.
Sample: 0,00 1.000,00
Vue.component('my-currency-input', {
template: `
<div>
<input type="text" v-model="formattedCurrencyValue" @blur="focusOut"/>
</div>`,
data: function() {
return {
currencyValue: 0,
formattedCurrencyValue: "0.00"
}
},
methods: {
focusOut: function() {
// Recalculate the currencyValue after ignoring "$" and "," in user input
this.currencyValue = parseFloat(this.formattedCurrencyValue.replace(/[^\d\.]/g, ""))
// Ensure that it is not NaN. If so, initialize it to zero.
// This happens if user provides a blank input or non-numeric input like "abc"
if (isNaN(this.currencyValue)) {
this.currencyValue = 0
}
// Format display value based on calculated currencyValue
this.formattedCurrencyValue = this.currencyValue.toFixed(2).replace(/(\d)(?=(\d{3})+(?:\.\d+)?$)/g, "$1,")
},
}
});
new Vue({
el: '#app'
});