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 >
@@ -47,6 +59,7 @@ export default {
4759 options: [],
4860 selectedCountries: [],
4961 isLoading: false ,
62+ valueMap: {},
5063 };
5164 },
5265 watch: {
@@ -57,14 +70,34 @@ export default {
5770
5871 },
5972 methods: {
60- checkNotOtherAndSendData (val ) {
61- if (val !== ' Other' ) {
62- this .$emit (' valueChanged' , val);
73+ checkAndSendData () {
74+ if (this .selected ) {
75+ if (this .selected .includes (' Other' )) {
76+ if (! _ .isEmpty (this .valueMap )) {
77+ this .valueMap [" Other" ] = this .otherInput ;
78+ }
79+ }
80+ let out = null ;
81+ if (this .multipleAllowed ) {
82+ if (! _ .isEmpty (this .valueMap )) {
83+ out = _ .map (this .selected , v => this .valueMap [v]);
84+ } else if (this .selected .includes (' Other' )) {
85+ out = [... this .selected .slice (0 , - 1 ), this .otherInput ];
86+ } else {
87+ out = [... this .selected ]
88+ }
89+ } else {
90+ if (! _ .isEmpty (this .valueMap )) {
91+ out = this .valueMap [this .selected ];
92+ } else if (this .selected === ' Other' ) {
93+ out = this .otherInput ;
94+ } else {
95+ out = this .selected ;
96+ }
97+ }
98+ this .$emit (' valueChanged' , out);
6399 }
64100 },
65- sendData (val ) {
66- this .$emit (' valueChanged' , [this .selected , val]);
67- },
68101 limitText (count ) {
69102 return ` and ${ count} other countries` ;
70103 },
@@ -82,6 +115,9 @@ export default {
82115 const activeValueChoices = _ .filter (v[' http://schema.org/name' ], ac => ac[' @language' ] === this .selected_language );
83116 return (activeValueChoices[0 ][' @value' ]);
84117 });
118+ this .options .forEach ((key , index ) => {
119+ this .valueMap [key] = this .constraints [' http://schema.repronim.org/choices' ][index][' http://schema.repronim.org/value' ][0 ][' @value' ];
120+ });
85121 } else if (this .constraints [' http://schema.repronim.org/choices' ].length === 1 ) { // choice list defined in external file
86122 axios .get (this .constraints [' http://schema.repronim.org/choices' ][0 ][' @value' ])
87123 .then ((resp ) => {
@@ -97,12 +133,17 @@ export default {
97133 multipleAllowed () {
98134 if (this .constraints [' http://schema.repronim.org/multipleChoice' ]) {
99135 // console.log(94, this.constraints[this.reprotermsUrl+'multipleChoice']);
100- return true ;
101- } return false ;
136+ return this .constraints [' http://schema.repronim.org/multipleChoice' ][0 ][' @value' ];
137+ }
138+ return false ;
102139 },
103140 checkOther () {
104- if (this .selected === ' Other' ) {
105- return true ;
141+ if (this .selected ) {
142+ if (this .multipleAllowed ) {
143+ return this .selected .includes (' Other' );
144+ } else {
145+ return this .selected === ' Other' ;
146+ }
106147 }
107148 return false ;
108149 },
0 commit comments