summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/subscription_select.js
blob: 7206bbd710972a26c1b5e74190e24d8dce5e53fe (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
import $ from 'jquery';
import { __ } from './locale';

export default function subscriptionSelect() {
  $('.js-subscription-event').each((i, element) => {
    const fieldName = $(element).data('fieldName');

    return $(element).glDropdown({
      selectable: true,
      fieldName,
      toggleLabel(selected, el, instance) {
        let label = __('Subscription');
        const $item = instance.dropdown.find('.is-active');
        if ($item.length) {
          label = $item.text();
        }
        return label;
      },
      clicked(options) {
        return options.e.preventDefault();
      },
      id(obj, el) {
        return $(el).data('id');
      },
    });
  });
}