Class: Trestle::Form::Fields::Select
- Inherits:
-
Trestle::Form::Field
- Object
- Trestle::Form::Field
- Trestle::Form::Fields::Select
- Defined in:
- lib/trestle/form/fields/select.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Choices
Instance Attribute Summary collapse
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#html_options ⇒ Object
readonly
Returns the value of attribute html_options.
Attributes inherited from Trestle::Form::Field
#block, #builder, #name, #options, #template
Instance Method Summary collapse
- #default_choices ⇒ Object
- #default_html_options ⇒ Object
- #field ⇒ Object
-
#initialize(builder, template, name, choices = nil, options = {}, html_options = {}, &block) ⇒ Select
constructor
A new instance of Select.
Methods inherited from Trestle::Form::Field
#defaults, #errors, #extract_options!, #form_group, #render
Constructor Details
#initialize(builder, template, name, choices = nil, options = {}, html_options = {}, &block) ⇒ Select
Returns a new instance of Select.
7 8 9 10 11 12 |
# File 'lib/trestle/form/fields/select.rb', line 7 def initialize(builder, template, name, choices=nil, ={}, ={}, &block) super(builder, template, name, , &block) @choices = Choices.new(choices || default_choices) @html_options = .merge() end |
Instance Attribute Details
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
5 6 7 |
# File 'lib/trestle/form/fields/select.rb', line 5 def choices @choices end |
#html_options ⇒ Object (readonly)
Returns the value of attribute html_options.
5 6 7 |
# File 'lib/trestle/form/fields/select.rb', line 5 def @html_options end |
Instance Method Details
#default_choices ⇒ Object
22 23 24 |
# File 'lib/trestle/form/fields/select.rb', line 22 def default_choices builder.object.send(name) if builder.object end |
#default_html_options ⇒ Object
18 19 20 |
# File 'lib/trestle/form/fields/select.rb', line 18 def Trestle::Options.new(class: ["form-control"], data: { enable_select2: true }) end |
#field ⇒ Object
14 15 16 |
# File 'lib/trestle/form/fields/select.rb', line 14 def field builder.raw_select(name, choices, , , &block) end |