Welcome to mirror list, hosted at ThFree Co, Russian Federation.

select2_helper.rb « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 691f84f39d477335d54c845799abc892bf2278e0 (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
# Select2 ajax programmatic helper
# It allows you to select value from select2
#
# Params
#   value - real value of selected item
#   opts - options containing css selector
#
# Usage:
#
#   select2(2, from: '#user_ids')
#

module Select2Helper
  def select2(value, options={})
    raise "Must pass a hash containing 'from'" if not options.is_a?(Hash) or not options.has_key?(:from)

    selector = options[:from]

    if options[:multiple]
      execute_script("$('#{selector}').select2('val', ['#{value}'], true);")
    else
      execute_script("$('#{selector}').select2('val', '#{value}', true);")
    end
  end
end