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_optionsObject



4
5
6
# File 'lib/formtastic/inputs/select_one_input.rb', line 4

def input_options
  super.merge include_blank: false
end

#input_wrapping(&block) ⇒ Object



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

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



28
29
30
31
# File 'lib/formtastic/inputs/select_one_input.rb', line 28

def search_box
  @opts ||= {id: nil, class: 'search-select', placeholder: options[:placeholder], 'data-remote-collection': options[:remote_collection], 'data-search': options[:search_param] ? options[:search_param] : 'name_contains', 'data-text': options[:text_key] ? options[:text_key] : 'name', 'data-value': options[:value_key] ? options[:value_key] : 'id', 'data-msg': options[:msg_items]}
  template.text_field_tag( nil, '', @opts )
end

#select_htmlObject



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

def select_html
  selected = object.send( input_name )
  sel = ''
  collection.each do |item|
    if item[1] == selected
      sel = template.options_for_select( [item], selected ) if item[1] == selected
      break
    end
  end
  builder.select(input_name, sel, input_options, input_html_options.merge( 'data-select': 'src' ) )
end

#to_htmlObject



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

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