Radio and dropdown fixes

This commit is contained in:
Samuel Elliott 2018-03-03 00:03:19 +00:00
parent 05c08ca51f
commit 2c6ae62c7e
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
8 changed files with 16 additions and 31 deletions

View File

@ -17,7 +17,7 @@ export default class MultipleChoiceOption {
} }
get id() { get id() {
return this.args.id; return this.args.id || this.value;
} }
get text() { get text() {

View File

@ -68,7 +68,7 @@ export default class Setting {
} }
merge(newSetting, emit_multi = true) { merge(newSetting, emit_multi = true) {
return this.setValue(newSetting.value, emit_multi); return this.setValue(newSetting.args ? newSetting.args.value : newSetting.value, emit_multi);
} }
setValue(value, emit_multi = true, emit = true) { setValue(value, emit_multi = true, emit = true) {
@ -105,7 +105,7 @@ export default class Setting {
strip() { strip() {
return { return {
id: this.id, id: this.id,
value: this.value value: this.args.value
}; };
} }

View File

@ -26,7 +26,7 @@ export default class DropdownSetting extends Setting {
} }
set value(value) { set value(value) {
const selected = this.options.find(option => option.id === value); const selected = this.options.find(option => option.value === value);
if (selected) this.setValue(selected.id); if (selected) this.setValue(selected.id);
else this.setValue(value); else this.setValue(value);
} }
@ -40,7 +40,7 @@ export default class DropdownSetting extends Setting {
} }
set selected_option(selected_option) { set selected_option(selected_option) {
this.args.value = this.options.find(option => option.id === selected_option.id).id; this.args.value = selected_option.id;
} }
toSCSS() { toSCSS() {

View File

@ -26,7 +26,7 @@ export default class RadioSetting extends Setting {
} }
set value(value) { set value(value) {
const selected = this.options.find(option => option.id === value); const selected = this.options.find(option => option.value === value);
if (selected) this.setValue(selected.id); if (selected) this.setValue(selected.id);
else this.setValue(value); else this.setValue(value);
} }
@ -40,7 +40,7 @@ export default class RadioSetting extends Setting {
} }
set selected_option(selected_option) { set selected_option(selected_option) {
this.value = this.options.find(option => option.id === selected_option.id).id; this.args.value = selected_option.id;
} }
toSCSS() { toSCSS() {

View File

@ -12,10 +12,10 @@
<div class="bd-form-dropdown"> <div class="bd-form-dropdown">
<div class="bd-title"> <div class="bd-title">
<h3 v-if="setting.text">{{setting.text}}</h3> <h3 v-if="setting.text">{{setting.text}}</h3>
<Dropdown v-if="!setting.fullwidth" :options="setting.options" :selected="setting.args.value" :disabled="setting.disabled" :change="change" /> <Dropdown v-if="!setting.fullwidth" :options="setting.options" :selected="setting.value" :disabled="setting.disabled" :change="change" />
</div> </div>
<div class="bd-hint">{{setting.hint}}</div> <div class="bd-hint">{{setting.hint}}</div>
<Dropdown v-if="setting.fullwidth" :options="setting.options" :selected="setting.args.value" :disabled="setting.disabled" :change="change" /> <Dropdown v-if="setting.fullwidth" :options="setting.options" :selected="setting.value" :disabled="setting.disabled" :change="change" />
</div> </div>
</template> </template>
<script> <script>

View File

@ -26,11 +26,6 @@
props: ['setting', 'change'], props: ['setting', 'change'],
components: { components: {
RadioGroup RadioGroup
},
methods: {
selectOption(option) {
this.change(option.id);
}
} }
} }
</script> </script>

View File

@ -11,13 +11,13 @@
<template> <template>
<div class="bd-dropdown" :class="{'bd-active': active, 'bd-disabled': disabled}"> <div class="bd-dropdown" :class="{'bd-active': active, 'bd-disabled': disabled}">
<div class="bd-dropdown-current" @click="() => active = !active && !disabled"> <div class="bd-dropdown-current" @click="() => active = !active && !disabled">
<span class="bd-dropdown-text">{{ getOptionText(selected) }}</span> <span class="bd-dropdown-text">{{ getSelectedText() }}</span>
<span class="bd-dropdown-arrow-wrap"> <span class="bd-dropdown-arrow-wrap">
<span class="bd-dropdown-arrow"></span> <span class="bd-dropdown-arrow"></span>
</span> </span>
</div> </div>
<div class="bd-dropdown-options bd-flex bd-flex-col" ref="options" v-if="active"> <div class="bd-dropdown-options bd-flex bd-flex-col" ref="options" v-if="active">
<div class="bd-dropdown-option" v-for="option in options" :class="{'bd-dropdown-option-selected': selected === option.id}" @click="selectOption(option)">{{ option.text }}</div> <div class="bd-dropdown-option" v-for="option in options" :class="{'bd-dropdown-option-selected': selected === option.value}" @click="change(option.value)">{{ option.text }}</div>
</div> </div>
</div> </div>
</template> </template>
@ -30,14 +30,9 @@
}; };
}, },
methods: { methods: {
getOptionText(value) { getSelectedText() {
let matching = this.options.filter(opt => opt.id === value); const selected_option = this.options.find(option => option.value === this.selected);
if (matching.length == 0) return ""; return selected_option ? selected_option.text : this.selected;
else return matching[0].text;
},
selectOption(option) {
this.active = false;
this.change(option.id);
} }
}, },
mounted() { mounted() {

View File

@ -10,7 +10,7 @@
<template> <template>
<div class="bd-radio-group" :class="{'bd-disabled': disabled}"> <div class="bd-radio-group" :class="{'bd-disabled': disabled}">
<label class="bd-radio" v-for="option in options" :class="{'bd-radio-selected': selected === option.id}" @click="selectOption(option)"> <label class="bd-radio" v-for="option in options" :class="{'bd-radio-selected': selected === option.value}" @click="change(option.value)">
<div class="bd-radio-control-wrap"> <div class="bd-radio-control-wrap">
<svg class="bd-radio-control" name="Checkmark" width="18" height="18" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><polyline stroke="#3e82e5" stroke-width="2" points="3.5 9.5 7 13 15 5"></polyline></g></svg> <svg class="bd-radio-control" name="Checkmark" width="18" height="18" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><polyline stroke="#3e82e5" stroke-width="2" points="3.5 9.5 7 13 15 5"></polyline></g></svg>
</div> </div>
@ -20,11 +20,6 @@
</template> </template>
<script> <script>
export default { export default {
props: ['options', 'selected', 'disabled', 'change'], props: ['options', 'selected', 'disabled', 'change']
methods: {
selectOption(option) {
this.change(option.id);
}
}
} }
</script> </script>