Skip to content

Commit ecbbbd3

Browse files
committed
fix selection behavior for single and multiple select, and other option.
1 parent b567fed commit ecbbbd3

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

src/components/Inputs/SelectInput/SelectInput.vue

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,37 @@
33
<multiselect v-if=" inputType=== 'select' && this.constraints['http://schema.org/itemListElement']"
44
v-model="selected" :options="this.options" :searchable="false"
55
:show-labels="false"
6-
placeholder="Pick a value" @input="checkNotOtherAndSendData">
6+
placeholder="Pick a value">
7+
</multiselect>
8+
<multiselect v-else-if="multipleAllowed" v-model="selected" id="ajax"
9+
placeholder="Type to search"
10+
:options="this.options" :multiple="true"
11+
:searchable="true"
12+
:internal-search="true" :clear-on-select="false"
13+
:close-on-select="true" :options-limit="300"
14+
:limit="5" :limit-text="limitText" :max-height="600"
15+
:show-no-results="false" :hide-selected="true">
716
</multiselect>
817
<multiselect v-else v-model="selected" id="ajax"
918
placeholder="Type to search"
10-
:options="this.options" :multiple="multipleAllowed"
19+
:options="this.options"
1120
:searchable="true"
1221
:internal-search="true" :clear-on-select="false"
1322
:close-on-select="true" :options-limit="300"
1423
:limit="5" :limit-text="limitText" :max-height="600"
15-
:show-no-results="false" :hide-selected="true"
16-
@input="checkNotOtherAndSendData">
24+
:show-no-results="false" :hide-selected="false">
1725
<span slot="noResult">{{ $t('select-invalid-query')}}</span>
1826
</multiselect>
1927
<div v-if="checkOther" id="ifOther" style="display: block;">
20-
<br><b-form-input v-model="otherInput" placeholder="Please describe" @change="sendData">
21-
</b-form-input>
28+
<br>
29+
<b-form-input v-model="otherInput" placeholder="Please describe">
30+
</b-form-input>
2231
</div>
32+
<br>
33+
<b-form v-if="this.selected" @submit="checkAndSendData">
34+
<b-btn type="submit">{{ $t('submit-button')}}</b-btn>
35+
</b-form>
2336
</div>
24-
2537
</template>
2638

2739
<script>
@@ -57,14 +69,19 @@ export default {
5769
5870
},
5971
methods: {
60-
checkNotOtherAndSendData(val) {
61-
if (val !== 'Other') {
62-
this.$emit('valueChanged', val);
72+
checkAndSendData() {
73+
if (this.selected) {
74+
if (this.selected.includes('Other')) {
75+
if (this.multipleAllowed) {
76+
this.$emit('valueChanged', [...this.selected.slice(0, -1), this.otherInput]);
77+
} else {
78+
this.$emit('valueChanged', this.otherInput);
79+
}
80+
} else {
81+
this.$emit('valueChanged', this.selected);
82+
}
6383
}
6484
},
65-
sendData(val) {
66-
this.$emit('valueChanged', [this.selected, val]);
67-
},
6885
limitText(count) {
6986
return `and ${count} other countries`;
7087
},
@@ -97,12 +114,13 @@ export default {
97114
multipleAllowed() {
98115
if (this.constraints['http://schema.repronim.org/multipleChoice']) {
99116
// console.log(94, this.constraints[this.reprotermsUrl+'multipleChoice']);
100-
return true;
101-
} return false;
117+
return this.constraints['http://schema.repronim.org/multipleChoice'][0]['@value'];
118+
}
119+
return false;
102120
},
103121
checkOther() {
104-
if (this.selected === 'Other') {
105-
return true;
122+
if (this.selected) {
123+
return this.selected.includes('Other');
106124
}
107125
return false;
108126
},

0 commit comments

Comments
 (0)