Class: Formtastic::Inputs::SelectOneInput

Inherits:
SelectInput
  • Object
show all
Defined in:
lib/formtastic/inputs/select_one_input.rb

Instance Method Summary collapse

Instance Method Details

#input_wrapping(&block) ⇒ Object

def input_options

super.merge include_blank: false

end



10
11
12
13
14
15
# File 'lib/formtastic/inputs/select_one_input.rb', line 10

def input_wrapping(&block)
  template.(options[:filter_form] ? :div : :li,
    [template.capture(&block), error_html, hint_html].join("\n").html_safe,
    wrapper_html_options
  )
end

#search_boxObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/formtastic/inputs/select_one_input.rb', line 29

def search_box
  # TODO: remove text_key in next major version
  opts = {
    id: nil,
    class: 'search-select',
    placeholder: options[:placeholder],
    'data-counter-limit': options[:counter_limit].to_i,
    'data-msg': options[:msg_items],
    'data-remote-collection': options[:remote_collection],
    'data-search': options[:search_param] || 'name_contains',
    'data-text': options[:member_label] || options[:text_key] || 'name',
    'data-value': options[:value_key] || 'id'
  }
  template.text_field_tag(nil, '', opts)
end

#select_htmlObject



45
46
47
48
49
50
# File 'lib/formtastic/inputs/select_one_input.rb', line 45

def select_html
  selected = options[:selected] || object.send(input_name)
  opts = input_html_options.merge('data-select': 'src')
  opts['data-include-blank'] = '1' if input_options[:include_blank]
  template.select_tag input_name, template.options_for_select(collection, selected), input_options.merge(opts)
end

#to_htmlObject



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/formtastic/inputs/select_one_input.rb', line 17

def to_html
  opts = { class: 'select-one-inputs' }
  input_wrapping do
    label_html <<
    template.(:div, opts) do
      search_box <<
      select_html <<
      template.(:span, '', class: 'status')
    end
  end
end