Class: Conjoin::FormBuilder::SelectInput
- Defined in:
- lib/conjoin/inputs/select.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Input
#app, #data, #options, #record
Instance Method Summary collapse
Methods inherited from Input
#errors?, #id, #initialize, #nested_name, #render
Constructor Details
This class inherits a constructor from Conjoin::FormBuilder::Input
Instance Method Details
#display ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/conjoin/inputs/select.rb', line 4 def display = .delete :append_button content = mab do # automatically add a prompt by default [:prompt] = 'true' unless .key? :prompt [:class] += ' selectize' selected_value = .delete :value select do opts = { value: '' } if prompt = .delete(:prompt) opts['selected'] = 'selected' unless selected_value option opts do text! prompt.to_s == 'true' ? 'Please Choose One.' : prompt end end if not [:group] .invert.each do |name, value| option render_opts(value, selected_value, opts) do text (name != name.upcase ? name.titleize : name) end end else .each do |group_select, group| optgroup label: group.to_s.titleize do group_select.each do |value, name| option render_opts(value, selected_value, opts) do text name.titleize end end end end end end end if not content else mab do div class: 'input-group' do text! content div class: 'input-group-btn' do class: 'btn btn-primary', type: 'button', 'on-click-get' => [:href] do text [:text] end end end end end end |
#render_opts(value, selected_value, opts) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/conjoin/inputs/select.rb', line 61 def render_opts value, selected_value, opts opts = { value: value } if selected_value.is_a? ActiveRecord::Associations::CollectionProxy opts['selected'] = 'selected' if selected_value.map(&:id).include? value else opts['selected'] = 'selected' if selected_value.to_s == value.to_s end opts end |