Skip to content

Commit fa2acf1

Browse files
committed
Use selectOptions in selectEx
1 parent 42b4fcb commit fa2acf1

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

src/fields/core/fieldChecklist.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
if (typeof item["value"] !== "undefined") {
5858
return item.value;
5959
} else {
60-
throw "value is not defined. If you want to use another key name, add a `value` property under `checklistOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/checklist.html#checklist-field-with-object-values";
60+
throw "`value` is not defined. If you want to use another key name, add a `value` property under `checklistOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/checklist.html#checklist-field-with-object-values";
6161
}
6262
}
6363
} else {
@@ -72,7 +72,7 @@
7272
if (typeof item["name"] !== "undefined") {
7373
return item.name;
7474
} else {
75-
throw "name is not defined. If you want to use another key name, add a `name` property under `checklistOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/checklist.html#checklist-field-with-object-values";
75+
throw "`name` is not defined. If you want to use another key name, add a `name` property under `checklistOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/checklist.html#checklist-field-with-object-values";
7676
}
7777
}
7878
} else {

src/fields/core/fieldRadios.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
if (typeof item["value"] !== "undefined") {
3737
return item.value;
3838
} else {
39-
throw "value is not defined. If you want to use another key name, add a `value` property under `radiosOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/radios.html#radios-field-with-object-values";
39+
throw "`value` is not defined. If you want to use another key name, add a `value` property under `radiosOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/radios.html#radios-field-with-object-values";
4040
}
4141
}
4242
} else {
@@ -51,7 +51,7 @@
5151
if (typeof item["name"] !== "undefined") {
5252
return item.name;
5353
} else {
54-
throw "name is not defined. If you want to use another key name, add a `name` property under `radiosOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/radios.html#radios-field-with-object-values";
54+
throw "`name` is not defined. If you want to use another key name, add a `name` property under `radiosOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/radios.html#radios-field-with-object-values";
5555
}
5656
}
5757
} else {

src/fields/core/fieldSelect.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
if (typeof item["id"] !== "undefined") {
3636
return item.id;
3737
} else {
38-
throw "id is not defined. If you want to use another key name, add a `value` property under `selectOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/select.html#select-field-with-object-items";
38+
throw "`id` is not defined. If you want to use another key name, add a `value` property under `selectOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/select.html#select-field-with-object-items";
3939
}
4040
}
4141
} else {
@@ -51,7 +51,7 @@
5151
if (typeof item["name"] !== "undefined") {
5252
return item.name;
5353
} else {
54-
throw "name is not defined. If you want to use another key name, add a `name` property under `selectOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/select.html#select-field-with-object-items";
54+
throw "`name` is not defined. If you want to use another key name, add a `name` property under `selectOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/select.html#select-field-with-object-items";
5555
}
5656
}
5757
} else {

src/fields/optional/fieldSelectEx.vue

+29-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template lang="pug">
22
select.selectpicker(v-model="value", :disabled="disabled", :multiple="schema.multiSelect", :title="schema.placeholder", data-width="100%", :name="schema.inputName")
33
option(:disabled="schema.required", v-if="schema.multiSelect !== true", :value="null", :selected="value == undefined")
4-
option(v-for="item in items", :value="getItemID(item)") {{ getItemName(item) }}
4+
option(v-for="item in items", :value="getItemValue(item)") {{ getItemName(item) }}
55
</template>
66

77
<script>
@@ -23,18 +23,37 @@
2323
},
2424
2525
methods: {
26-
getItemID(item) {
27-
if (isObject(item) && item.id)
28-
return item.id;
29-
30-
return item;
26+
getItemValue(item) {
27+
if (isObject(item)){
28+
if (typeof this.schema["selectOptions"] !== "undefined" && typeof this.schema["selectOptions"]["value"] !== "undefined") {
29+
return item[this.schema.selectOptions.value];
30+
} else {
31+
// Use 'id' instead of 'value' cause of backward compatibility
32+
if (typeof item["id"] !== "undefined") {
33+
return item.id;
34+
} else {
35+
throw "`id` is not defined. If you want to use another key name, add a `value` property under `selectOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/select.html#select-field-with-object-items";
36+
}
37+
}
38+
} else {
39+
return item;
40+
}
3141
},
3242
3343
getItemName(item) {
34-
if (isObject(item) && item.name)
35-
return item.name;
36-
37-
return item;
44+
if (isObject(item)){
45+
if (typeof this.schema["selectOptions"] !== "undefined" && typeof this.schema["selectOptions"]["name"] !== "undefined") {
46+
return item[this.schema.selectOptions.name];
47+
} else {
48+
if (typeof item["name"] !== "undefined") {
49+
return item.name;
50+
} else {
51+
throw "`name` is not defined. If you want to use another key name, add a `name` property under `selectOptions` in the schema. https://icebob.gitbooks.io/vueformgenerator/content/fields/select.html#select-field-with-object-items";
52+
}
53+
}
54+
} else {
55+
return item;
56+
}
3857
}
3958
},
4059

0 commit comments

Comments
 (0)