Class: Ramaze::InstanceForm

Inherits:
Form show all
Defined in:
lib/ramaze/helper/form.rb

Overview

Form for instances of the model class

Constant Summary

Constants inherited from Form

Form::DATE_GENERIC, Form::TIME_GENERIC

Instance Attribute Summary

Attributes inherited from Form

#object, #options

Instance Method Summary collapse

Methods inherited from Form

#field_for, #initialize, pick, #to_s

Constructor Details

This class inherits a constructor from Ramaze::Form

Instance Method Details

#args_for(hash) ⇒ Object



271
272
273
274
# File 'lib/ramaze/helper/form.rb', line 271

def args_for(hash)
  name = hash[:name]
  [ name, @object.send(name) ]
end

#field_boolean(name, value) ⇒ Object

<input type=“checkbox” …



237
238
239
240
241
242
243
# File 'lib/ramaze/helper/form.rb', line 237

def field_boolean(name, value)
  if value
    checkbox :name => name, :value => value, :checked => :checked
  else
    checkbox :name => name, :value => value
  end
end

#field_date(name, value) ⇒ Object



245
246
247
248
249
250
251
# File 'lib/ramaze/helper/form.rb', line 245

def field_date(name, value)
  field_date_generic do |sel, range|
    [ "<select name='#{name}[#{sel}]'>",
      option_range_selected(range, value.send(sel)),
      "</select>" ]
  end
end

#field_input(name, value) ⇒ Object

<input type=‘text’ name=‘name’ value=‘value’ />



223
224
225
# File 'lib/ramaze/helper/form.rb', line 223

def field_input(name, value)
  "<input type='text' name='#{name}' value='#{value}'/>"
end

#field_integer(name, value) ⇒ Object

<input type=“text” name=“name” value=“value” />



232
233
234
# File 'lib/ramaze/helper/form.rb', line 232

def field_integer(name, value)
  field_input(name, value)
end

#field_textarea(name, value) ⇒ Object



227
228
229
# File 'lib/ramaze/helper/form.rb', line 227

def field_textarea(name, value)
  "<textarea name='#{name}'>#{value}</textarea>"
end

#field_time(name, value) ⇒ Object



253
254
255
256
257
258
259
# File 'lib/ramaze/helper/form.rb', line 253

def field_time(name, value)
  field_time_generic do |sel, range|
    [ "<select name='#{name}[#{sel}]'>",
      option_range_selected(range, value.send(sel)),
      "</select>" ]
  end
end

#object_classObject

Class for @object, atm Sequel specific?



277
278
279
# File 'lib/ramaze/helper/form.rb', line 277

def object_class
  @object.class
end

#option_range_selected(range, value) ⇒ Object



261
262
263
264
265
266
267
268
269
# File 'lib/ramaze/helper/form.rb', line 261

def option_range_selected(range, value)
  range.map do |r|
    if r == value
      option(r, :value => r, :selected => :selected)
    else
      option(r, :value => r)
    end
  end
end