Class: Trestle::Form::Field
- Inherits:
-
Object
- Object
- Trestle::Form::Field
show all
- 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::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
Instance Method Summary
collapse
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, options={}, &block)
@builder, @template, @name, @block = builder, template, name, block
assign_options!(options)
normalize_options!
end
|
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
4
5
6
|
# File 'lib/trestle/form/field.rb', line 4
def block
@block
end
|
#builder ⇒ Object
Returns the value of attribute builder.
4
5
6
|
# File 'lib/trestle/form/field.rb', line 4
def builder
@builder
end
|
#name ⇒ Object
Returns the value of attribute name.
4
5
6
|
# File 'lib/trestle/form/field.rb', line 4
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
4
5
6
|
# File 'lib/trestle/form/field.rb', line 4
def options
@options
end
|
#template ⇒ Object
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
39
40
41
|
# File 'lib/trestle/form/field.rb', line 39
def defaults
Trestle::Options.new(readonly: readonly?)
end
|
#disabled? ⇒ Boolean
43
44
45
|
# File 'lib/trestle/form/field.rb', line 43
def disabled?
options[:disabled]
end
|
#errors ⇒ Object
15
16
17
|
# File 'lib/trestle/form/field.rb', line 15
def errors
error_keys.map { |key| builder.errors(key) }.flatten
end
|
#field ⇒ Object
35
36
37
|
# File 'lib/trestle/form/field.rb', line 35
def field
raise NotImplementedError
end
|
19
20
21
22
23
24
25
26
27
|
# File 'lib/trestle/form/field.rb', line 19
def form_group(opts={})
if @wrapper
@builder.form_group(name, @wrapper.merge(opts)) do
yield
end
else
yield
end
end
|
#normalize_options! ⇒ Object
51
52
53
54
|
# File 'lib/trestle/form/field.rb', line 51
def normalize_options!
assign_error_class!
end
|
#readonly? ⇒ Boolean
47
48
49
|
# File 'lib/trestle/form/field.rb', line 47
def readonly?
options[:readonly] || admin.try(:readonly?)
end
|
#render ⇒ Object
29
30
31
32
33
|
# File 'lib/trestle/form/field.rb', line 29
def render
form_group do
field
end
end
|