Class: Merb::Helpers::Form::Builder::Form

Inherits:
Base
  • Object
show all
Defined in:
lib/merb_helpers/form/builder.rb

Direct Known Subclasses

FormWithErrors, ResourcefulForm

Instance Method Summary collapse

Methods inherited from Base

#add_css_class, #bound_check_box, #bound_radio_button, #bound_radio_group, #bound_select, #bound_text_area, #concat, #fake_out_method, #fieldset, #form, #initialize, #process_form_attrs, #unbound_radio_group, #update_bound_check_box, #update_bound_select, #update_unbound_check_box

Methods included from Tag

#close_tag, #open_tag, #self_closing_tag, #tag

Constructor Details

This class inherits a constructor from Merb::Helpers::Form::Builder::Base

Instance Method Details

#button(contents, attrs = {}) ⇒ Object



311
312
313
# File 'lib/merb_helpers/form/builder.rb', line 311

def button(contents, attrs = {})
  label(attrs) + super
end

#label(contents, attrs = {}) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/merb_helpers/form/builder.rb', line 290

def label(contents, attrs = {})
  if contents.is_a?(Hash)
    attrs    = contents
    contents = attrs.delete(:label)
  end
  if contents
    for_attr = attrs[:id] ? {:for => attrs[:id]} : {}
    tag(:label, contents, for_attr)
  else
    ""
  end
end

#radio_group_item(method, attrs) ⇒ Object



337
338
339
340
341
342
343
344
# File 'lib/merb_helpers/form/builder.rb', line 337

def radio_group_item(method, attrs)
  unless attrs[:id]
    attrs.merge!(:id => "#{@name}_#{method}_#{attrs[:value]}")
  end

  attrs.merge!(:label => attrs[:label] || attrs[:value])
  super
end

#submit(value, attrs = {}) ⇒ Object



315
316
317
# File 'lib/merb_helpers/form/builder.rb', line 315

def submit(value, attrs = {})
  label(attrs) + super
end

#unbound_check_box(attrs = {}) ⇒ Object



327
328
329
330
# File 'lib/merb_helpers/form/builder.rb', line 327

def unbound_check_box(attrs = {})
  label_text = label(attrs)
  super + label_text
end

#unbound_hidden_field(attrs = {}) ⇒ Object



346
347
348
349
# File 'lib/merb_helpers/form/builder.rb', line 346

def unbound_hidden_field(attrs = {})
  attrs.delete(:label)
  super
end

#unbound_radio_button(attrs = {}) ⇒ Object



332
333
334
335
# File 'lib/merb_helpers/form/builder.rb', line 332

def unbound_radio_button(attrs = {})
  label_text = label(attrs)
  super + label_text
end

#unbound_select(attrs = {}) ⇒ Object



323
324
325
# File 'lib/merb_helpers/form/builder.rb', line 323

def unbound_select(attrs = {})
  label(attrs) + super
end

#unbound_text_area(contents, attrs = {}) ⇒ Object



319
320
321
# File 'lib/merb_helpers/form/builder.rb', line 319

def unbound_text_area(contents, attrs = {})
  label(attrs) + super
end

#update_bound_controls(method, attrs, type) ⇒ Object



277
278
279
280
# File 'lib/merb_helpers/form/builder.rb', line 277

def update_bound_controls(method, attrs, type)
  attrs.merge!(:id => "#{@name}_#{method}") unless attrs[:id]
  super
end

#update_unbound_controls(attrs, type) ⇒ Object



282
283
284
285
286
287
288
# File 'lib/merb_helpers/form/builder.rb', line 282

def update_unbound_controls(attrs, type)
  case type
  when "text", "radio", "password", "hidden", "checkbox", "file"
    add_css_class(attrs, type)
  end
  super
end