cleaner inputs for Wealth
This commit is contained in:
28
lootalot_front/src/components/NumberInput.vue
Normal file
28
lootalot_front/src/components/NumberInput.vue
Normal file
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<input type="text"
|
||||
class="input"
|
||||
:class="{'is-danger': has_error}"
|
||||
:value="value"
|
||||
@input="checkError"
|
||||
></input>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: ["value"],
|
||||
data () {
|
||||
return { has_error: false};
|
||||
},
|
||||
methods: {
|
||||
checkError (ev) {
|
||||
const newValue = ev.target.value;
|
||||
this.has_error = isNaN(newValue);
|
||||
this.$emit(
|
||||
'input',
|
||||
// Do the conversion if valid
|
||||
this.has_error ? newValue : Number(newValue)
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user