Skip to content

Commit 0f48c30

Browse files
author
Lionel Bijaoui
committed
radios field now support array of string or array of objects (with name and value properties) by default. If radiosOptions is defined, these key can be replaced by other name, but this is no longer mandatory to use the array of object notation.
1 parent f4bd438 commit 0f48c30

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/fields/core/fieldRadios.vue

+28-21
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,41 @@
2828
},
2929
3030
methods: {
31-
onSelection(item) {
32-
if (isObject(item) && this.schema.radiosOptions.value && item[this.schema.radiosOptions.value]){
33-
this.value = item[this.schema.radiosOptions.value];
34-
} else{
35-
this.value = item;
36-
}
37-
},
3831
getItemValue(item) {
39-
if (isObject(item) && this.schema.radiosOptions.value && item[this.schema.radiosOptions.value]){
40-
return item[this.schema.radiosOptions.value];
32+
if (isObject(item)){
33+
if (typeof this.schema["radiosOptions"] !== "undefined" && typeof this.schema["radiosOptions"]["value"] !== "undefined") {
34+
return item[this.schema.radiosOptions.value];
35+
} else {
36+
if (typeof item["value"] !== "undefined") {
37+
return item.value
38+
} else {
39+
throw "value is not defined.\r If you want to use another key name, add a `value` property under `radiosOptions` in the schema.\r https://icebob.gitbooks.io/vueformgenerator/content/fields/radios.html#radios-field-with-object-values";
40+
}
41+
}
42+
} else {
43+
return item;
4144
}
42-
43-
return item;
4445
},
4546
getItemName(item) {
46-
if (isObject(item) && this.schema.radiosOptions.name && item[this.schema.radiosOptions.name]){
47-
return item[this.schema.radiosOptions.name];
47+
if (isObject(item)){
48+
if (typeof this.schema["radiosOptions"] !== "undefined" && typeof this.schema["radiosOptions"]["name"] !== "undefined") {
49+
return item[this.schema.radiosOptions.name];
50+
} else {
51+
if (typeof item["name"] !== "undefined") {
52+
return item.name
53+
} else {
54+
throw "name is not defined.\r If you want to use another key name, add a `name` property under `radiosOptions` in the schema.\r https://icebob.gitbooks.io/vueformgenerator/content/fields/radios.html#radios-field-with-object-values";
55+
}
56+
}
57+
} else {
58+
return item;
4859
}
49-
50-
return item;
60+
},
61+
onSelection(item) {
62+
this.value = this.getItemValue(item);
5163
},
5264
isItemChecked(item) {
53-
let currentValue;
54-
if (isObject(item) && this.schema.radiosOptions.value && item[this.schema.radiosOptions.value]){
55-
currentValue = item[this.schema.radiosOptions.value];
56-
} else{
57-
currentValue = item;
58-
}
65+
let currentValue = this.getItemValue(item);
5966
return (currentValue === this.value);
6067
},
6168
}

0 commit comments

Comments
 (0)