<template>
  <kyb-input v-bind="$attrs" v-model="valueStr" @input="input" @blur="$emit('blur',$event)" />
</template>
<script>
export default {
  name: 'kyb-input-number',
  model: {
    prop: 'value',
    event: 'input'
  },
  props: {
    value: Number
  },
  watch: {
    value(old) {
      this.fixMData(old)
    }
  },
  data() {
    return {
      valueStr: ''
    }
  },
  methods: {
    fixMData(value) {
      this.valueStr = value != null && value !== undefined ? value + '' : value
    },
    input($event) {
      this.$emit('input', isNaN($event) ? $event : parseFloat($event))
    }
  },
  created() {
    this.fixMData(this.value)
  }
}
</script>
