Method: Redmineup::FormTagHelper#select2_tag
- Defined in:
- lib/redmineup/helpers/form_tag_helper.rb
#select2_tag(name, option_tags = nil, options = {}) ⇒ Object Also known as: select2
Allows include select2 into your views.
Examples
select2_tag 'city_id', '<option value="1">Lisbon</option>...'
select2_tag 'city_id', (...)
select2_tag 'tag_list', nil, :multiple => true, :data => [{ id: 0, text: 'deal' }, ...], :tags => true, :include_hidden => false %>
select2_tag 'tag_list', (...), :multiple => true, :style => 'width: 100%;', :url => '/tags', :placeholder => '+ add tag', :tags => true %>
You may use select_tag options and additional options.
Additional options
-
:urlAllows searches for remote data using the ajax. -
:dataLoad dropdown options from a local array ifurloption not set. -
:placeholderSupports displaying a placeholder value. -
:include_hiddenAdds hidden field after select whenmultipleoption true. Default value true. -
:allow_clearProvides support for clearable selections. Default value false. -
:min_input_lengthMinimum number of characters required to start a search. Default value 0. -
:format_stateDefines template of search results in the drop-down. -
:tagsUsed to enable tagging feature.
Note: The HTML specification says when multiple parameter passed to select and all options got deselected web browsers do not send any value to server.
In case if you don’t want the helper to generate this hidden field you can specify include_hidden: false option.
Note: Select2 assets must be available on a page.
To include select2 assets to a page, you need to use the helper select2_assets.
For example:
<% content_for :header_tags do %>
<%= select2_assets %>
<% end %>
Also aliased as: select2
select2 'city_id', (...)
40 41 42 43 44 45 46 47 48 |
# File 'lib/redmineup/helpers/form_tag_helper.rb', line 40 def select2_tag(name, = nil, = {}) s = select_tag(name, , ) if [:multiple] && .fetch(:include_hidden, true) s << hidden_field_tag("#{name}[]", '') end s + javascript_tag("select2Tag('#{sanitize_to_id(name)}', #{options.to_json});") end |