Class: Trestle::Form::Field
- Inherits:
-
Object
- Object
- Trestle::Form::Field
- Defined in:
- lib/trestle/form/field.rb
Direct Known Subclasses
Trestle::Form::Fields::CheckBox, Trestle::Form::Fields::CollectionCheckBoxes, Trestle::Form::Fields::CollectionRadioButtons, Trestle::Form::Fields::CollectionSelect, Trestle::Form::Fields::DateSelect, Trestle::Form::Fields::DatetimeSelect, Trestle::Form::Fields::FileField, Trestle::Form::Fields::FormControl, Trestle::Form::Fields::FormGroup, Trestle::Form::Fields::GroupedCollectionSelect, Trestle::Form::Fields::RadioButton, Trestle::Form::Fields::RangeField, Trestle::Form::Fields::Select, Trestle::Form::Fields::StaticField, Trestle::Form::Fields::TimeSelect, Trestle::Form::Fields::TimeZoneSelect
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #defaults ⇒ Object
- #errors ⇒ Object
- #extract_options! ⇒ Object
- #field ⇒ Object
- #form_group(opts = {}) ⇒ Object
-
#initialize(builder, template, name, options = {}, &block) ⇒ Field
constructor
A new instance of Field.
- #render ⇒ Object
Constructor Details
#initialize(builder, template, name, options = {}, &block) ⇒ Field
Returns a new instance of Field.
8 9 10 11 12 13 |
# File 'lib/trestle/form/field.rb', line 8 def initialize(builder, template, name, ={}, &block) @builder, @template, @name, @block = builder, template, name, block @options = defaults.merge() end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/trestle/form/field.rb', line 4 def block @block end |
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
4 5 6 |
# File 'lib/trestle/form/field.rb', line 4 def builder @builder end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/trestle/form/field.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/trestle/form/field.rb', line 4 def @options end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/trestle/form/field.rb', line 4 def template @template end |
Instance Method Details
#defaults ⇒ Object
37 38 39 |
# File 'lib/trestle/form/field.rb', line 37 def defaults Trestle::Options.new(readonly: admin.readonly?) end |
#errors ⇒ Object
15 16 17 18 19 |
# File 'lib/trestle/form/field.rb', line 15 def errors errors = builder.errors(name) errors += builder.errors(name.to_s.sub(/_id$/, '')) if name.to_s =~ /_id$/ errors end |
#extract_options! ⇒ Object
41 42 43 |
# File 'lib/trestle/form/field.rb', line 41 def @wrapper = (*Fields::FormGroup::WRAPPER_OPTIONS).merge(.delete(:wrapper)) end |
#field ⇒ Object
33 34 35 |
# File 'lib/trestle/form/field.rb', line 33 def field raise NotImplementedError end |
#form_group(opts = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/trestle/form/field.rb', line 21 def form_group(opts={}) @builder.form_group(name, @wrapper.merge(opts)) do yield end end |
#render ⇒ Object
27 28 29 30 31 |
# File 'lib/trestle/form/field.rb', line 27 def render form_group do field end end |