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
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/conjoin/inputs/select.rb', line 15 def display # We don't need the type .delete :type = .delete :append_button = .delete :append_split_button if [:multiple] [:name] += '[]' end content = mab do # automatically add a prompt by default [:prompt] = 'true' unless .key? :prompt [:class] += ' selectize' unless .delete(:selectize) == false 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.downcase ? 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 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 elsif = .shift 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 if .length class: 'btn btn-primary dropdown-toggle', 'data-toggle' => "dropdown", type: 'button' do span class: 'caret' end ul class: 'dropdown-menu pull-right', role: 'menu' do .each do |b| li do a href: 'javascript:{};', 'on-click-get' => b[:href] do text b[:text] end end end end end end end end else content end end |
#render_opts(value, selected_value, opts) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/conjoin/inputs/select.rb', line 107 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 elsif selected_value.is_a? Array opts['selected'] = 'selected' if selected_value.include? value.to_s else opts['selected'] = 'selected' if selected_value.to_s == value.to_s end opts end |
#select_options ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/conjoin/inputs/select.rb', line 4 def values_select = {} values = data.record_class.send(data.field_name).values values.each do |value| values_select[value] = value end values_select end |