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_wrapping(&block) ⇒ Object
def input_options super.merge include_blank: false end.
- #search_box ⇒ Object
- #select_html ⇒ Object
- #to_html ⇒ Object
Instance Method Details
#input_wrapping(&block) ⇒ Object
def input_options
super.merge include_blank: false
end
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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/formtastic/inputs/select_one_input.rb', line 27 def search_box # TODO: remove text_key in next major version opts = { id: nil, class: 'search-select', placeholder: [:placeholder], 'data-counter-limit': [:counter_limit].to_i, 'data-msg': [:msg_items], 'data-remote-collection': [: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_html ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/formtastic/inputs/select_one_input.rb', line 43 def select_html selected = [:selected] ? [: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 opts = .merge( 'data-select': 'src' ) opts['data-include-blank'] = '1' if [:include_blank] builder.select(input_name, sel, , opts ) end |
#to_html ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# 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, '', class: 'status' ) end end end |