class Formtastic::Inputs::SelectManyInput

Public Instance Methods

buttons_html() click to toggle source
# File lib/formtastic/inputs/select_many_input.rb, line 35
def buttons_html
  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() click to toggle source
# File lib/formtastic/inputs/select_many_input.rb, line 25
def hidden_input
  template.content_tag(:div, class: 'values', 'data-name': input_html_options[:name]) do
    values = object.send(input_name)
    values = [values] if values.is_a? Integer
    values.each do |value|
      template.concat template.hidden_field_tag(input_html_options[:name], value, {id: nil})
    end if values
  end
end
search_box_html() click to toggle source
# File lib/formtastic/inputs/select_many_input.rb, line 44
def search_box_html
  opts = {
    id: nil,
    class: 'search-select',
    placeholder: options.delete(:placeholder),
    'data-counter-limit': options[:counter_limit].to_i,
    'data-remote-collection': options[:'data-remote-collection'],
    'data-search': options[:search_param] ? options[:search_param] : 'name_contains',
    'data-text': options[:member_label] ? options[:member_label] : (options[:text_key] ? options[:text_key] : 'name'),
    'data-value': options[:value_key] ? options[:value_key] : 'id',
  }
  template.text_field_tag(nil, '', opts)
end
select_dst_html() click to toggle source
# File lib/formtastic/inputs/select_many_input.rb, line 79
def select_dst_html
  selected = options[: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: options[:size] || 4,
    'data-select': 'dst'
  }
  template.select_tag "#{input_name}_dst", template.options_for_select(coll), input_options.merge(opts)
end
select_src_html() click to toggle source
# File lib/formtastic/inputs/select_many_input.rb, line 58
def select_src_html
  coll =
    if options[:'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: options[:size] || 4,
    'data-select': 'src'
  }
  template.select_tag "#{input_name}_src", template.options_for_select(coll), input_options.merge(opts)
end
to_html() click to toggle source
# File lib/formtastic/inputs/select_many_input.rb, line 6
def to_html
  options[:'data-remote-collection'] = options.delete(:remote_collection)
  opts = { class: 'select-many-inputs' }
  opts[:sortable] = options.delete(:sortable) if options[: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 <<
      buttons_html <<
      select_dst_html
    end
  end
end