Class: FoxTail::FormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/helpers/fox_tail/form_builder.rb

Instance Method Summary collapse

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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::AutocompleteComponent.new(url, options), &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 button(value = nil, options = {}, &block)
  if value.is_a? Hash
    options = value
    value = nil
  end

  options = objectify_component_options nil, options
  options[:value] ||= value
  component = FoxTail::ButtonComponent.new(options)
  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 button_group(options = {}, &block)
  options = objectify_component_options nil, options
  @template.render FoxTail::ButtonGroupComponent.new(options), &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, options = {}, checked_value = "1", unchecked_value = "0", &block)
  options = objectify_component_options method, options
  options[:checked_value] = checked_value
  options[:unchecked_value] = unchecked_value
  @template.render FoxTail::CheckboxComponent.new(options), &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, options = {}, html_options = {}, &block)
  choices = collection.map { |item| [item.send(text_method), item.send(value_method)] }
  select method, choices, options, html_options, &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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::DropzoneComponent.new(options), &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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::InputErrorListComponent.new(options), &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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::FileInputComponent.new(options), &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, options = {}, html_options = {}, &block)
  select method, nil, options, html_options 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, options = {}, &block)
  if text.is_a?(Hash)
    options = text
    text = nil
  end

  options = objectify_component_options method, options
  component = FoxTail::HelperTextComponent.new options
  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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::InputComponent.new(options), &block
end

#input_group(options = {}, &block) ⇒ Object



188
189
190
191
# File 'app/helpers/fox_tail/form_builder.rb', line 188

def input_group(options = {}, &block)
  options = objectify_component_options nil, options
  @template.render FoxTail::InputGroupComponent.new(options), &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, options = {}, &block)
  if text.is_a? Hash
    options = text
    text = nil
  end

  options = objectify_component_options method, options
  component = FoxTail::LabelComponent.new options
  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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::PasswordInputComponent.new(options), &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 radio_button(method, tag_value, options = {}, &block)
  options = objectify_component_options method, options
  options[:value] = tag_value
  @template.render FoxTail::RadioButtonComponent.new(options), &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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::RangeComponent.new(options), &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, options = {}, &block)
  input_field method, options.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, options = {}, html_options = {}, &block)
  options = objectify_component_options(method, options.merge(html_options))
  options[:placeholder] = options.delete(:placeholder) || options.delete(:prompt)
  options[:choices] = choices

  @template.render FoxTail::SelectComponent.new(options) 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 show_password_button(method, options = {}, &block)
  options = objectify_component_options method, options
  component = FoxTail::ShowPasswordComponent.new options
  @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, options = {}, &block)
  if value.is_a?(Hash)
    options = value
    value = nil
  end

  options[:type] = :submit

  button value, options, &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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  options = objectify_component_options method, options
  @template.render FoxTail::TextareaComponent.new(options), &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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  input_field method, options.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, options = {}, &block)
  input_field method, options.merge(type: :week), &block
end