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

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/merb_helpers.rb

Instance Method Summary collapse

Instance Method Details

#bound_date_field(method, attrs = {}) ⇒ Object



13
14
15
16
17
# File 'app/helpers/merb_helpers.rb', line 13

def bound_date_field(method, attrs = {})
  name = control_name(method)
  update_bound_controls(method, attrs, "text")
  unbound_date_field({:name => name, :value => @obj.send(method)}.merge(attrs))
end

#unbound_date_field(attrs) ⇒ Object



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
# File 'app/helpers/merb_helpers.rb', line 19

def unbound_date_field(attrs)
  update_unbound_controls(attrs, "date")
  if attrs[:name] =~ /\[(.*)\]/
    date = @obj.send($1)
  end
  date = DateTime::now() if date.nil?
  
  month_attrs = attrs.merge(
    :class        => "date month",
    :selected     => date.month,
    :name         => attrs[:name] + '[month]',
    :id           => attrs[:id] + '_month',
    :collection   => (1..12).map{|i|[i, DateTime::MONTHNAMES[i]]}
  )
  
  day_attrs = attrs.merge(
    :class        => "date day",
    :selected     => date.day.to_s,
    :name         => attrs[:name] + '[day]',
    :id           => attrs[:id] + '_day',
    :collection   => (1..31).map{|i|i.to_s},
    :label        => nil
  )
  
  year_attrs = attrs.merge(
    :class        => "date year",
    :selected     => date.year.to_s,
    :name         => attrs[:name] + '[year]',
    :id           => attrs[:id] + '_year',
    :collection   => (1900..Time.now.year).map{|i|i.to_s}.reverse,
    :label        => nil
  )
  
  unbound_select(month_attrs) + unbound_select(day_attrs) + unbound_select(year_attrs)
end