Module: Redmineup::FormTagHelper
- Defined in:
- lib/redmineup/helpers/form_tag_helper.rb
Instance Method Summary collapse
- #format_datetime(time) ⇒ Object
- #format_datetime_date(time) ⇒ Object
-
#select2_tag(name, option_tags = nil, options = {}) ⇒ Object
(also: #select2)
Allows include select2 into your views.
-
#tag_list_field_tag(name, value = [], options = {}) ⇒ Object
Renders a select2 tag field for a tag list (standalone, no form object).
-
#transform_to_select2(type, options = {}) ⇒ Object
Transforms select filters of
typefields into select2.
Instance Method Details
#format_datetime(time) ⇒ Object
101 102 103 104 105 |
# File 'lib/redmineup/helpers/form_tag_helper.rb', line 101 def format_datetime(time) formated_time = format_time(time, false) formated_date = ::I18n.l(time.to_date, format: '%Y-%m-%d') "#{formated_date} #{formated_time}" end |
#format_datetime_date(time) ⇒ Object
107 108 109 110 |
# File 'lib/redmineup/helpers/form_tag_helper.rb', line 107 def format_datetime_date(time) formated_date = ::I18n.l(time.to_date, format: '%Y-%m-%d') "#{formated_date}" end |
#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', options_for_select(...)
select2_tag 'tag_list', nil, :multiple => true, :data => [{ id: 0, text: 'deal' }, ...], :tags => true, :include_hidden => false %>
select2_tag 'tag_list', options_for_select(...), :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', options_for_select(...)
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)}', #{.to_json});") end |
#tag_list_field_tag(name, value = [], options = {}) ⇒ Object
Renders a select2 tag field for a tag list (standalone, no form object). Analogous to text_field_tag.
Example
tag_list_field_tag 'entry[tag_list]', entry.tag_list,
url: (taggable_type: 'DriveEntry')
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/redmineup/helpers/form_tag_helper.rb', line 58 def tag_list_field_tag(name, value = [], = {}) url = .delete(:url) taggable_type = .delete(:taggable_type) width = .delete(:width) project_id = .delete(:project_id) placeholder = .delete(:placeholder) select2_tag( name, (value, value), { multiple: true, width: width || '95%', url: url || (taggable_type: taggable_type, project_id: project_id), placeholder: placeholder || l(:lable_redmineup_add_tag), tags: true }.merge() ) end |
#transform_to_select2(type, options = {}) ⇒ Object
Transforms select filters of type fields into select2
Examples
transform_to_select2 'tags', url:
transform_to_select2 'people', format_state: 'formatStateWithAvatar', min_input_length: 1, url: '/managers'
Options
-
:urlDefines URL to search remote data using the ajax. -
:format_stateDefines template of search results in the drop-down. -
:min_input_lengthMinimum number of characters required to start a search. Default value 0. -
:widthSets the width of the control. Default value ‘60%’. -
:multipleSupports multi-value select box. If set to false the selection will not allow multiple choices. Default value true.
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 %>
97 98 99 |
# File 'lib/redmineup/helpers/form_tag_helper.rb', line 97 def transform_to_select2(type, = {}) javascript_tag("setSelect2Filter('#{type}', #{.to_json});") unless type.empty? end |