Skip to content

Commit

Permalink
Use selectOptions in selectEx
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Jul 1, 2017
1 parent 42b4fcb commit fa2acf1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/fields/core/fieldChecklist.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
if (typeof item["value"] !== "undefined") {
return item.value;
} else {
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";
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";
}
}
} else {
Expand All @@ -72,7 +72,7 @@
if (typeof item["name"] !== "undefined") {
return item.name;
} else {
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";
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";
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/fields/core/fieldRadios.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
if (typeof item["value"] !== "undefined") {
return item.value;
} else {
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";
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";
}
}
} else {
Expand All @@ -51,7 +51,7 @@
if (typeof item["name"] !== "undefined") {
return item.name;
} else {
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";
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";
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/fields/core/fieldSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if (typeof item["id"] !== "undefined") {
return item.id;
} else {
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";
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";
}
}
} else {
Expand All @@ -51,7 +51,7 @@
if (typeof item["name"] !== "undefined") {
return item.name;
} else {
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";
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";
}
}
} else {
Expand Down
39 changes: 29 additions & 10 deletions src/fields/optional/fieldSelectEx.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
select.selectpicker(v-model="value", :disabled="disabled", :multiple="schema.multiSelect", :title="schema.placeholder", data-width="100%", :name="schema.inputName")
option(:disabled="schema.required", v-if="schema.multiSelect !== true", :value="null", :selected="value == undefined")
option(v-for="item in items", :value="getItemID(item)") {{ getItemName(item) }}
option(v-for="item in items", :value="getItemValue(item)") {{ getItemName(item) }}
</template>

<script>
Expand All @@ -23,18 +23,37 @@
},
methods: {
getItemID(item) {
if (isObject(item) && item.id)
return item.id;
return item;
getItemValue(item) {
if (isObject(item)){
if (typeof this.schema["selectOptions"] !== "undefined" && typeof this.schema["selectOptions"]["value"] !== "undefined") {
return item[this.schema.selectOptions.value];
} else {
// Use 'id' instead of 'value' cause of backward compatibility
if (typeof item["id"] !== "undefined") {
return item.id;
} else {
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";
}
}
} else {
return item;
}
},
getItemName(item) {
if (isObject(item) && item.name)
return item.name;
return item;
if (isObject(item)){
if (typeof this.schema["selectOptions"] !== "undefined" && typeof this.schema["selectOptions"]["name"] !== "undefined") {
return item[this.schema.selectOptions.name];
} else {
if (typeof item["name"] !== "undefined") {
return item.name;
} else {
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";
}
}
} else {
return item;
}
}
},
Expand Down

0 comments on commit fa2acf1

Please sign in to comment.