gitlab-org--gitlab-foss/spec/support/select2_helper.rb

26 lines
603 B
Ruby
Raw Normal View History

2013-07-29 06:46:00 -04:00
# 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 = {})
2015-06-22 14:52:41 -04:00
raise ArgumentError, 'options must be a Hash' unless options.kind_of?(Hash)
2015-06-22 14:52:41 -04:00
selector = options.fetch(:from)
if options[:multiple]
execute_script("$('#{selector}').select2('val', ['#{value}'], true);")
else
execute_script("$('#{selector}').select2('val', '#{value}', true);")
end
end
end