class Merb::Helpers::Form::Builder::Form

Public Instance Methods

button(contents, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 363
def button(contents, attrs = {})
  unbound_label(attrs) + super
end
label(contents, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 301
def label(contents, attrs = {})
  if contents
    if contents.is_a?(Hash)
      label_attrs = contents
      contents = label_attrs.delete(:title)
    else
      label_attrs = attrs
    end
    tag(:label, contents, label_attrs)
  else
    ""
  end
end
submit(value, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 367
def submit(value, attrs = {})
  unbound_label(attrs) + super
end
unbound_check_box(attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 340
def unbound_check_box(attrs = {})
  label_text = unbound_label(attrs)
  super + label_text
end
unbound_hidden_field(attrs = {}) click to toggle source
Calls superclass method
# File lib/merb-helpers/form/builder.rb, line 345
def unbound_hidden_field(attrs = {})
  attrs.delete(:label)
  super
end
unbound_label(attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 323
def unbound_label(attrs = {})
  if attrs[:id]
    label_attrs = {:for => attrs[:id]}
  elsif attrs[:name]
    label_attrs = {:for => attrs[:name]}
  else
    label_attrs = {}
  end

  label_option = attrs.delete(:label)
  if label_option.is_a? Hash
    label(label_attrs.merge(label_option))
  else
    label(label_option, label_attrs)
  end
end
unbound_radio_button(attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 350
def unbound_radio_button(attrs = {})
  label_text = unbound_label(attrs)
  super + label_text
end
unbound_select(attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 355
def unbound_select(attrs = {})
  unbound_label(attrs) + super
end
unbound_text_area(contents, attrs = {}) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 359
def unbound_text_area(contents, attrs = {})
  unbound_label(attrs) + super
end

Private Instance Methods

radio_group_item(method, attrs) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 393
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
update_bound_controls(method, attrs, type) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 373
def update_bound_controls(method, attrs, type)
  attrs.merge!(:id => "#{@name}_#{method}") unless attrs[:id]
  super
end
update_unbound_controls(attrs, type) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 378
def update_unbound_controls(attrs, type)
  if attrs[:name] && !attrs[:id]
    attrs.merge!(:id => valid_xhtml_id(attrs[:name]))
  end
  case type
  when "text", "radio", "password", "hidden", "checkbox", "file"
    add_css_class(attrs, type)
  end
  super
end
valid_xhtml_id(candidate) click to toggle source
# File lib/merb-helpers/form/builder.rb, line 389
def valid_xhtml_id(candidate)
  candidate.to_s.gsub(/(\[|\])/, '_')
end