summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/select2_select.vue
blob: 6d2612556ffc1a63b1cf82c1fe1d3bb0d4517b66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<script>
import $ from 'jquery';
import 'select2';

export default {
  name: 'Select2Select',
  props: {
    options: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    value: {
      type: String,
      required: false,
      default: '',
    },
  },

  mounted() {
    $(this.$refs.dropdownInput)
      .val(this.value)
      .select2(this.options)
      .on('change', event => this.$emit('input', event.target.value));
  },

  beforeDestroy() {
    $(this.$refs.dropdownInput).select2('destroy');
  },
};
</script>

<template>
  <input ref="dropdownInput" type="hidden" />
</template>