debian-mirror-gitlab/spec/support/select2_helper.rb

26 lines
601 B
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
# 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-09-11 14:41:01 +05:30
raise ArgumentError, 'options must be a Hash' unless options.kind_of?(Hash)
2014-09-02 18:07:02 +05:30
2015-09-11 14:41:01 +05:30
selector = options.fetch(:from)
2014-09-02 18:07:02 +05:30
if options[:multiple]
2015-04-26 12:48:37 +05:30
execute_script("$('#{selector}').select2('val', ['#{value}'], true);")
2014-09-02 18:07:02 +05:30
else
2015-04-26 12:48:37 +05:30
execute_script("$('#{selector}').select2('val', '#{value}', true);")
2014-09-02 18:07:02 +05:30
end
end
end