Class: FoxTail::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- FoxTail::FormBuilder
- Defined in:
- app/helpers/fox_tail/form_builder.rb
Instance Method Summary collapse
- #autocomplete_field(method, url, options = {}, &block) ⇒ Object
- #button(value = nil, options = {}, &block) ⇒ Object
- #button_group(options = {}, &block) ⇒ Object
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0", &block) ⇒ Object
- #collection_select(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
- #color_field(method, options = {}, &block) ⇒ Object
- #date_field(method, options = {}, &block) ⇒ Object
- #datetime_field(method, options = {}, &block) ⇒ Object (also: #datetime_local_field)
- #dropzone_field(method, options = {}, &block) ⇒ Object
- #email_field(method, options = {}, &block) ⇒ Object
- #error_list(method, options = {}, &block) ⇒ Object
- #file_field(method, options = {}, &block) ⇒ Object
- #grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}, &block) ⇒ Object
- #help_text(method, text = nil, options = {}, &block) ⇒ Object
- #input_field(method, options = {}, &block) ⇒ Object
- #input_group(options = {}, &block) ⇒ Object
- #label(method, text = nil, options = {}, &block) ⇒ Object
- #month_field(method, options = {}, &block) ⇒ Object
- #number_field(method, options = {}, &block) ⇒ Object
- #password_field(method, options = {}, &block) ⇒ Object
- #radio_button(method, tag_value, options = {}, &block) ⇒ Object
- #range_field(method, options = {}, &block) ⇒ Object
- #search_field(method, options = {}, &block) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
- #show_password_button(method, options = {}, &block) ⇒ Object
- #submit(value = nil, options = {}, &block) ⇒ Object
- #telephone_field(method, options = {}, &block) ⇒ Object (also: #phone_field)
- #text_area(method, options = {}, &block) ⇒ Object
- #text_field(method, options = {}, &block) ⇒ Object
- #time_field(method, options = {}, &block) ⇒ Object
- #url_field(method, options = {}, &block) ⇒ Object
- #week_field(method, options = {}, &block) ⇒ Object
Instance Method Details
#autocomplete_field(method, url, options = {}, &block) ⇒ Object
101 102 103 104 |
# File 'app/helpers/fox_tail/form_builder.rb', line 101 def autocomplete_field(method, url, = {}, &block) = method, @template.render FoxTail::AutocompleteComponent.new(url, ), &block end |
#button(value = nil, options = {}, &block) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/helpers/fox_tail/form_builder.rb', line 170 def (value = nil, = {}, &block) if value.is_a? Hash = value value = nil end = nil, [:value] ||= value component = FoxTail::ButtonComponent.new() component.with_content value if value.present? @template.render component, &block end |
#button_group(options = {}, &block) ⇒ Object
183 184 185 186 |
# File 'app/helpers/fox_tail/form_builder.rb', line 183 def ( = {}, &block) = nil, @template.render FoxTail::ButtonGroupComponent.new(), &block end |
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0", &block) ⇒ Object
126 127 128 129 130 131 |
# File 'app/helpers/fox_tail/form_builder.rb', line 126 def check_box(method, = {}, checked_value = "1", unchecked_value = "0", &block) = method, [:checked_value] = checked_value [:unchecked_value] = unchecked_value @template.render FoxTail::CheckboxComponent.new(), &block end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object
149 150 151 152 |
# File 'app/helpers/fox_tail/form_builder.rb', line 149 def collection_select(method, collection, value_method, text_method, = {}, = {}, &block) choices = collection.map { |item| [item.send(text_method), item.send(value_method)] } select method, choices, , , &block end |
#color_field(method, options = {}, &block) ⇒ Object
48 49 50 |
# File 'app/helpers/fox_tail/form_builder.rb', line 48 def color_field(method, = {}, &block) input_field method, .merge(type: :color), &block end |
#date_field(method, options = {}, &block) ⇒ Object
62 63 64 |
# File 'app/helpers/fox_tail/form_builder.rb', line 62 def date_field(method, = {}, &block) input_field method, .merge(type: :date), &block end |
#datetime_field(method, options = {}, &block) ⇒ Object Also known as: datetime_local_field
66 67 68 |
# File 'app/helpers/fox_tail/form_builder.rb', line 66 def datetime_field(method, = {}, &block) input_field method, .merge(type: :"datetime-local"), &block end |
#dropzone_field(method, options = {}, &block) ⇒ Object
121 122 123 124 |
# File 'app/helpers/fox_tail/form_builder.rb', line 121 def dropzone_field(method, = {}, &block) = method, @template.render FoxTail::DropzoneComponent.new(), &block end |
#email_field(method, options = {}, &block) ⇒ Object
88 89 90 |
# File 'app/helpers/fox_tail/form_builder.rb', line 88 def email_field(method, = {}, &block) input_field method, .merge(type: :email), &block end |
#error_list(method, options = {}, &block) ⇒ Object
34 35 36 37 |
# File 'app/helpers/fox_tail/form_builder.rb', line 34 def error_list(method, = {}, &block) = method, @template.render FoxTail::InputErrorListComponent.new(), &block end |
#file_field(method, options = {}, &block) ⇒ Object
116 117 118 119 |
# File 'app/helpers/fox_tail/form_builder.rb', line 116 def file_field(method, = {}, &block) = method, @template.render FoxTail::FileInputComponent.new(), &block end |
#grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {}, &block) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/helpers/fox_tail/form_builder.rb', line 154 def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, = {}, = {}, &block) select method, nil, , do |select_component| collection.each do |group| select_component.with_select_group group.send(group_label_method) do |group_component| group.send(group_method).each do |group_item| value = group_item.send option_key_method label = group_item.send option_value_method group_component.with_group_option(value).with_text(label) end end end capture select_component, &block if block end end |
#help_text(method, text = nil, options = {}, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/fox_tail/form_builder.rb', line 22 def help_text(method, text = nil, = {}, &block) if text.is_a?(Hash) = text text = nil end = method, component = FoxTail::HelperTextComponent.new component.with_content text if text.present? @template.render component, &block end |
#input_field(method, options = {}, &block) ⇒ Object
96 97 98 99 |
# File 'app/helpers/fox_tail/form_builder.rb', line 96 def input_field(method, = {}, &block) = method, @template.render FoxTail::InputComponent.new(), &block end |
#input_group(options = {}, &block) ⇒ Object
188 189 190 191 |
# File 'app/helpers/fox_tail/form_builder.rb', line 188 def input_group( = {}, &block) = nil, @template.render FoxTail::InputGroupComponent.new(), &block end |
#label(method, text = nil, options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/fox_tail/form_builder.rb', line 4 def label(method, text = nil, = {}, &block) if text.is_a? Hash = text text = nil end = method, component = FoxTail::LabelComponent.new component.with_content text if !block && text.present? @template.render component, &block end |
#month_field(method, options = {}, &block) ⇒ Object
76 77 78 |
# File 'app/helpers/fox_tail/form_builder.rb', line 76 def month_field(method, = {}, &block) input_field method, .merge(type: :month), &block end |
#number_field(method, options = {}, &block) ⇒ Object
92 93 94 |
# File 'app/helpers/fox_tail/form_builder.rb', line 92 def number_field(method, = {}, &block) input_field method, .merge(type: :number), &block end |
#password_field(method, options = {}, &block) ⇒ Object
43 44 45 46 |
# File 'app/helpers/fox_tail/form_builder.rb', line 43 def password_field(method, = {}, &block) = method, @template.render FoxTail::PasswordInputComponent.new(), &block end |
#radio_button(method, tag_value, options = {}, &block) ⇒ Object
133 134 135 136 137 |
# File 'app/helpers/fox_tail/form_builder.rb', line 133 def (method, tag_value, = {}, &block) = method, [:value] = tag_value @template.render FoxTail::RadioButtonComponent.new(), &block end |
#range_field(method, options = {}, &block) ⇒ Object
106 107 108 109 |
# File 'app/helpers/fox_tail/form_builder.rb', line 106 def range_field(method, = {}, &block) = method, @template.render FoxTail::RangeComponent.new(), &block end |
#search_field(method, options = {}, &block) ⇒ Object
52 53 54 |
# File 'app/helpers/fox_tail/form_builder.rb', line 52 def search_field(method, = {}, &block) input_field method, .merge(type: :search), &block end |
#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object
139 140 141 142 143 144 145 146 147 |
# File 'app/helpers/fox_tail/form_builder.rb', line 139 def select(method, choices = nil, = {}, = {}, &block) = (method, .merge()) [:placeholder] = .delete(:placeholder) || .delete(:prompt) [:choices] = choices @template.render FoxTail::SelectComponent.new() do |select| @template.capture select, &block if block end end |
#show_password_button(method, options = {}, &block) ⇒ Object
16 17 18 19 20 |
# File 'app/helpers/fox_tail/form_builder.rb', line 16 def (method, = {}, &block) = method, component = FoxTail::ShowPasswordComponent.new @template.render component, &block end |
#submit(value = nil, options = {}, &block) ⇒ Object
193 194 195 196 197 198 199 200 201 202 |
# File 'app/helpers/fox_tail/form_builder.rb', line 193 def submit(value = nil, = {}, &block) if value.is_a?(Hash) = value value = nil end [:type] = :submit value, , &block end |
#telephone_field(method, options = {}, &block) ⇒ Object Also known as: phone_field
56 57 58 |
# File 'app/helpers/fox_tail/form_builder.rb', line 56 def telephone_field(method, = {}, &block) input_field method, .merge(type: :tel), &block end |
#text_area(method, options = {}, &block) ⇒ Object
111 112 113 114 |
# File 'app/helpers/fox_tail/form_builder.rb', line 111 def text_area(method, = {}, &block) = method, @template.render FoxTail::TextareaComponent.new(), &block end |
#text_field(method, options = {}, &block) ⇒ Object
39 40 41 |
# File 'app/helpers/fox_tail/form_builder.rb', line 39 def text_field(method, = {}, &block) input_field method, .merge(type: :text), &block end |
#time_field(method, options = {}, &block) ⇒ Object
72 73 74 |
# File 'app/helpers/fox_tail/form_builder.rb', line 72 def time_field(method, = {}, &block) input_field method, .merge(type: :time), &block end |
#url_field(method, options = {}, &block) ⇒ Object
84 85 86 |
# File 'app/helpers/fox_tail/form_builder.rb', line 84 def url_field(method, = {}, &block) input_field method, .merge(type: :url), &block end |
#week_field(method, options = {}, &block) ⇒ Object
80 81 82 |
# File 'app/helpers/fox_tail/form_builder.rb', line 80 def week_field(method, = {}, &block) input_field method, .merge(type: :week), &block end |