Skip to content

Commit

Permalink
Fixed #234
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Jul 1, 2017
1 parent f7043b6 commit 42b4fcb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions dev/full/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ module.exports = {
values: [{
id: "admin",
name: "Administrator"
}, {
id: 0,
name: "Zero"
}, {
id: "moderator",
name: "Moderator"
Expand Down
39 changes: 29 additions & 10 deletions src/fields/core/fieldSelect.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
select.form-control(v-model="value", :disabled="disabled", :name="schema.inputName", :id="getFieldID(schema)")
option(v-if="!selectOptions.hideNoneSelectedText", :disabled="schema.required", :value="null", :selected="value == undefined") {{ selectOptions.noneSelectedText || "&lt;Nothing selected&gt;" }}
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 @@ -26,18 +26,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 42b4fcb

Please sign in to comment.