-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInput.vue
More file actions
73 lines (64 loc) · 2.07 KB
/
Copy pathInput.vue
File metadata and controls
73 lines (64 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<template>
<div class="input-group" :class="{'has-error': error.hasError, 'is-fullwidth': fullwidth}">
<input class="input" :type="type" :placeholder="placeholder" @blur="validateMask()" v-model="inputValue" v-if="type != 'currency' && type != 'textarea'">
<textarea class="input" :placeholder="placeholder" @blur="validateMask()" v-model="inputValue" v-if="type == 'textarea'"></textarea>
<input class="input" type="currency" :placeholder="placeholder" @blur="validateMask()" v-model="inputValue" v-if="type == 'currency'">
<span class="label">{{label}}</span>
<span class="error" v-if="error.hasError">{{error.message}}</span>
</div>
</template>
<script>
export default {
name: 'Input',
props: ['type', 'placeholder', 'value', 'required', 'label', 'min', 'max', 'fullwidth'],
data() {
return {
minValue: parseInt(this.min),
maxValue: parseInt(this.max),
error: {
hasError: false,
message: ''
}
}
},
computed: {
inputValue: {
get(){
return this.value || '';
},
set(val){
this.validate();
console.log('oie')
this.$emit('input', val);
}
}
},
methods: {
validateMask(){
this.validate();
if(!this.error.hasError){
}
},
validate(){
if(this.required && this.inputValue === ''){
this.error = {
hasError: true,
message: `The input is required!`
};
}else if(this.type === 'currency'){
if(this.inputValue < this.minValue){
this.error = {
hasError: true,
message: `The value must be greater than ${this.minValue}`
};
}else if(this.inputValue > this.maxValue){
this.error = {
hasError: true,
message: `The value must be smaller than ${this.maxValue}`
};
} else this.error = {hasError: false}
}else this.error = {hasError: false}
}
}
}
</script>