Class: Formtastic::Inputs::SelectOneInput
- Inherits:
-
SelectInput
- Object
- SelectInput
- Formtastic::Inputs::SelectOneInput
- Defined in:
- lib/formtastic/inputs/select_one_input.rb
Instance Method Summary collapse
- #input_options ⇒ Object
- #input_wrapping(&block) ⇒ Object
- #search_box ⇒ Object
- #select_html ⇒ Object
- #to_html ⇒ Object
Instance Method Details
#input_options ⇒ Object
4 5 6 |
# File 'lib/formtastic/inputs/select_one_input.rb', line 4 def 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.content_tag([:filter_form] ? :div : :li, [template.capture(&block), error_html, hint_html].join("\n").html_safe, ) end |
#search_box ⇒ Object
28 29 30 31 |
# File 'lib/formtastic/inputs/select_one_input.rb', line 28 def search_box @opts ||= {id: nil, class: 'search-select', placeholder: [:placeholder], 'data-remote-collection': [:remote_collection], 'data-search': [:search_param] ? [:search_param] : 'name_contains', 'data-text': [:text_key] ? [:text_key] : 'name', 'data-value': [:value_key] ? [:value_key] : 'id', 'data-msg': [:msg_items]} template.text_field_tag( nil, '', @opts ) end |
#select_html ⇒ Object
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.( [item], selected ) if item[1] == selected break end end builder.select(input_name, sel, , .merge( 'data-select': 'src' ) ) end |
#to_html ⇒ Object
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.content_tag( :div, opts ) do search_box << select_html << # template.content_tag( :span, '' ) << template.content_tag( :span, template.t( 'inputs.select_one.status' ), class: 'status' ) end end end |