Class: Formtastic::Inputs::SelectManyInput
- Inherits:
-
SelectInput
- Object
- SelectInput
- Formtastic::Inputs::SelectManyInput
- Defined in:
- lib/formtastic/inputs/select_many_input.rb
Instance Method Summary collapse
- #buttons_html ⇒ Object
- #hidden_input ⇒ Object
- #search_box_html ⇒ Object
- #select_dst_html ⇒ Object
- #select_src_html ⇒ Object
- #to_html ⇒ Object
Instance Method Details
#buttons_html ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/formtastic/inputs/select_many_input.rb', line 35 def template.content_tag(:div, class: 'buttons') do template.link_to('→'.html_safe, 'Javascript:void(0)', class: 'add') + template.link_to('←'.html_safe, 'Javascript:void(0)', class: 'remove') + template.link_to('↑'.html_safe, 'Javascript:void(0)', class: 'move_up') + template.link_to('↓'.html_safe, 'Javascript:void(0)', class: 'move_down') end end |
#hidden_input ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/formtastic/inputs/select_many_input.rb', line 25 def hidden_input template.content_tag(:div, class: 'values', 'data-name': [:name]) do values = object.send(input_name) values = [values] if values.is_a? Integer values.each do |value| template.concat template.hidden_field_tag([:name], value, {id: nil}) end if values end end |
#search_box_html ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/formtastic/inputs/select_many_input.rb', line 44 def search_box_html opts = { id: nil, class: 'search-select', placeholder: .delete(:placeholder), 'data-counter-limit': [:counter_limit].to_i, 'data-remote-collection': [:'data-remote-collection'], 'data-search': [:search_param] ? [:search_param] : 'name_contains', 'data-text': [:member_label] ? [:member_label] : ([:text_key] ? [:text_key] : 'name'), 'data-value': [:value_key] ? [:value_key] : 'id', } template.text_field_tag(nil, '', opts) end |
#select_dst_html ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/formtastic/inputs/select_many_input.rb', line 79 def select_dst_html selected = [:selected] || object.send(input_name) selected = [selected] if selected.is_a? Integer coll = selected ? collection.select { |option| selected.include?(option[1]) } : [] opts = { id: nil, include_blank: false, multiple: true, name: nil, size: [:size] || 4, 'data-select': 'dst' } template.select_tag nil, template.(coll), .merge(opts) end |
#select_src_html ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/formtastic/inputs/select_many_input.rb', line 58 def select_src_html coll = if [:'data-remote-collection'] [] else # TODO: add option unique ? selected = object.send(input_name) selected = [selected] if selected.is_a? Integer selected ? collection.select { |option| !selected.include?(option[1]) } : collection end opts = { id: nil, include_blank: false, multiple: true, name: nil, size: [:size] || 4, 'data-select': 'src' } template.select_tag nil, template.(coll), .merge(opts) end |
#to_html ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/formtastic/inputs/select_many_input.rb', line 6 def to_html [:'data-remote-collection'] = .delete(:remote_collection) opts = { class: 'select-many-inputs' } opts[:sortable] = .delete(:sortable) if [:sortable] input_wrapping do label_html << template.content_tag(:div, opts) do hidden_input << search_box_html << template.content_tag(:span, '', class: 'empty') << template.content_tag(:span, ::I18n.t('inputs.select_many.available'), class: 'available') << template.content_tag(:span, ::I18n.t('inputs.select_many.selected'), class: 'selected') << select_src_html << << select_dst_html end end end |