forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldRadios.vue
78 lines (68 loc) · 1.78 KB
/
fieldRadios.vue
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
74
75
76
77
78
<template lang="jade">
.radio-list(:disabled="disabled")
label(v-for="item in items")
input(type="radio", :disabled="disabled", :name="id", @click="onSelection(item)", :value="getItemValue(item)", :checked="isItemChecked(item)" )
| {{ getItemName(item) }}
</template>
<script>
import {isObject} from "lodash";
import abstractField from "./abstractField";
export default {
mixins: [ abstractField ],
computed: {
items() {
let values = this.schema.values;
if (typeof(values) == "function") {
return values.apply(this, [this.model, this.schema]);
} else {
return values;
}
},
id(){
return this.schema.model;
}
},
methods: {
onSelection(item) {
if (isObject(item) && this.schema.radiosOptions.value && item[this.schema.radiosOptions.value]){
this.value = item[this.schema.radiosOptions.value];
} else{
this.value = item;
}
},
getItemValue(item) {
if (isObject(item) && this.schema.radiosOptions.value && item[this.schema.radiosOptions.value]){
return item[this.schema.radiosOptions.value];
}
return item;
},
getItemName(item) {
if (isObject(item) && this.schema.radiosOptions.name && item[this.schema.radiosOptions.name]){
return item[this.schema.radiosOptions.name];
}
return item;
},
isItemChecked(item) {
let currentValue;
if (isObject(item) && this.schema.radiosOptions.value && item[this.schema.radiosOptions.value]){
currentValue = item[this.schema.radiosOptions.value];
} else{
currentValue = item;
}
return (currentValue === this.value);
},
}
};
</script>
<style lang="sass">
.vue-form-generator .field-radios {
.radio-list {
label {
display: block;
input[type="radio"]{
margin-right: 5px;
}
}
}
}
</style>