class Trestle::Form::Fields::Select

Attributes

choices[R]
html_options[R]

Public Class Methods

new(builder, template, name, choices=nil, options={}, html_options={}, &block) click to toggle source
Calls superclass method Trestle::Form::Field::new
# File lib/trestle/form/fields/select.rb, line 7
def initialize(builder, template, name, choices=nil, options={}, html_options={}, &block)
  super(builder, template, name, options, &block)

  @choices = choices || default_choices
  @choices = Choices.new(@choices) if @choices.nil? || @choices.is_a?(Enumerable)

  @html_options = default_html_options.merge(html_options)
end

Public Instance Methods

default_choices() click to toggle source
# File lib/trestle/form/fields/select.rb, line 24
def default_choices
  builder.object.send(name) if builder.object
end
default_html_options() click to toggle source
# File lib/trestle/form/fields/select.rb, line 20
def default_html_options
  Trestle::Options.new(class: ["form-control"], disabled: disabled? || readonly?, data: { enable_select2: true })
end
field() click to toggle source
# File lib/trestle/form/fields/select.rb, line 16
def field
  builder.raw_select(name, choices, options, html_options, &block)
end