Class: Nitro::Form::Control
- Inherits:
-
Object
- Object
- Nitro::Form::Control
- Includes:
- XhtmlHelper
- Defined in:
- lib/nitro/helper/form/controls.rb,
lib/nitro/helper/form/controls.rb
Overview
The controls map.
Direct Known Subclasses
ArrayControl, CheckboxControl, FixnumControl, HasManyControl, PasswordControl, RefersToControl, TextControl, TextareaControl
Instance Attribute Summary collapse
-
#obj ⇒ Object
readonly
Returns the value of attribute obj.
-
#prop ⇒ Object
(also: #rel)
readonly
Fetch the instance vars in a nice way use either rel or prop.
-
#value ⇒ Object
(also: #values)
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.fetch(obj, key, options = {}) ⇒ Object
Fetch a control, setup for ‘obj’ for a property, or relation or :symbol defaults to Control if not found.
Instance Method Summary collapse
-
#initialize(obj, key, options = {}) ⇒ Control
constructor
setup instance vars to use in methods.
-
#label ⇒ Object
Label item.
-
#on_populate(val) ⇒ Object
Custom callback to process the request information posted back from the form.
-
#render ⇒ Object
Main bulk of the control.
Methods included from XhtmlHelper
#date_select, #datetime_select, #hidden, #href_of, #js_popup, #link_to, #onclick_popup, #options, #popup, #submit, #time_select
Constructor Details
#initialize(obj, key, options = {}) ⇒ Control
setup instance vars to use in methods
32 33 34 35 36 37 |
# File 'lib/nitro/helper/form/controls.rb', line 32 def initialize(obj, key, = {}) @obj = obj @prop = key @value = [:value] || obj.send(key.name.to_sym) = end |
Instance Attribute Details
#obj ⇒ Object (readonly)
Returns the value of attribute obj.
25 26 27 |
# File 'lib/nitro/helper/form/controls.rb', line 25 def obj @obj end |
#prop ⇒ Object (readonly) Also known as: rel
Fetch the instance vars in a nice way use either rel or prop.
values/value contain the contents of the prop or rel, (values reads better for relations)
22 23 24 |
# File 'lib/nitro/helper/form/controls.rb', line 22 def prop @prop end |
#value ⇒ Object (readonly) Also known as: values
Returns the value of attribute value.
27 28 29 |
# File 'lib/nitro/helper/form/controls.rb', line 27 def value @value end |
Class Method Details
.fetch(obj, key, options = {}) ⇒ Object
Fetch a control, setup for ‘obj’ for a property, or relation or :symbol defaults to Control if not found
369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/nitro/helper/form/controls.rb', line 369 def self.fetch(obj, key, ={}) if key.kind_of? Og::Relation control_sym = key[:control] || key.class.to_s.demodulize.underscore.to_sym elsif key.kind_of? Property control_sym = key[:control] || key.klass.to_s.underscore.to_sym else control_sym = key.to_sym end default_to = .fetch(:default, Control) self.map.fetch(control_sym, Control).new(obj, key, ) end |
Instance Method Details
#label ⇒ Object
Label item. Override to customise
47 48 49 |
# File 'lib/nitro/helper/form/controls.rb', line 47 def label %{<label for="#{prop.name}">#{prop[:title] || prop.name.to_s.humanize}</label>} end |
#on_populate(val) ⇒ Object
Custom callback to process the request information posted back from the form
When Property.populate_object (or fill) is called with the :preprocess => true option then this method will get called before the value is pushed onto the object that is getting ‘filled’
Overide this on controls that require special mods to the incoming values
62 63 64 |
# File 'lib/nitro/helper/form/controls.rb', line 62 def on_populate(val) return val end |
#render ⇒ Object
Main bulk of the control. Overide to customise
41 42 43 |
# File 'lib/nitro/helper/form/controls.rb', line 41 def render "No view for this control" end |