0

I can get salary data from my database using vue js v-model like this

enter image description here

but i want to add data mask to look like this

enter image description here

here is my code for my retrieve, the field key salary / gaji is a double, i dont know how to add data mask using vue js, can anyone help me??

<div class="form-row">

      <div class="form-group col-md-6">

         <label class="col-form-label">Salary</label>
         <input type="text" class="form-control" v-model="nasabah.form.salary">

      </div>

  </div>
M Andre Juliansyah
  • 117
  • 1
  • 2
  • 14

3 Answers3

0

I hope this can help : v-mask package

susanta96
  • 89
  • 5
0

You can use a computed to format the displayed value in the input.

Vue.config.devtools = false;
Vue.config.productionTip = false;

var app = new Vue({
  el: '#app',
  data: {
    rawSalary: 0
  },
  methods: {
    onChange(e) {
    this.rawSalary = e.target.value;
    }
  },
  computed: {
    formattedSalary() {
      return this.rawSalary.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <label>Salary</label>
  <input type="text" :value="formattedSalary" @change="onChange">
  
  <div>rawSalary : {{ rawSalary }}</div>
</div>
Pierre Said
  • 3,660
  • 1
  • 16
  • 28
-1

You can use filter to format the number into currency, for example:

filters: {
  currencyFormat(val) {
    return (val).toFixed(2)
              .replace(/\d(?=(\d{3})+\.)/g, '$&,');
  }
}

Use pipes to use it on your template, for example:

<div>
  <input type="text" class="form-control" v-model="nasabah.form.salary | formatCurrency">
</div>

Please note that this will mutate your salary property with the formatted value

You can learn more about it here

tony19
  • 125,647
  • 18
  • 229
  • 307
faiqkaboel
  • 28
  • 4