Class: Bureaucrat::Widgets::RadioSelect

Inherits:
Select show all
Defined in:
lib/bureaucrat/widgets.rb

Constant Summary

Constants included from Utils

Utils::ESCAPES

Instance Attribute Summary

Attributes inherited from Select

#choices

Attributes inherited from Widget

#attrs, #is_required

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Select

#render_option, #render_options

Methods inherited from Widget

#build_attrs, #has_changed?, #hidden?, #initialize_copy, #needs_multipart?, #value_from_formdata

Methods included from Utils

#blank_value?, #conditional_escape, #escape, #flatatt, #format_string, #make_bool, #make_float, #mark_safe, #pretty_name

Constructor Details

#initialize(*args) ⇒ RadioSelect

Returns a new instance of RadioSelect.



494
495
496
497
498
# File 'lib/bureaucrat/widgets.rb', line 494

def initialize(*args)
  options = args.last.is_a?(Hash) ? args.last : {}
  @renderer = options.fetch(:renderer, renderer)
  super
end

Class Method Details

.id_for_label(id_) ⇒ Object



486
487
488
# File 'lib/bureaucrat/widgets.rb', line 486

def self.id_for_label(id_)
  id_.empty? ? id_ : id_ + '_0'
end

Instance Method Details

#get_renderer(name, value, attrs = nil, choices = []) ⇒ Object



500
501
502
503
504
505
506
# File 'lib/bureaucrat/widgets.rb', line 500

def get_renderer(name, value, attrs=nil, choices=[])
  value ||= ''
  str_value = value.to_s
  final_attrs = build_attrs(attrs)
  choices = @choices.to_a + choices.to_a
  @renderer.new(name, str_value, final_attrs, choices)
end

#render(name, value, attrs = nil, choices = []) ⇒ Object



508
509
510
# File 'lib/bureaucrat/widgets.rb', line 508

def render(name, value, attrs=nil, choices=[])
  get_renderer(name, value, attrs, choices).render
end

#rendererObject



490
491
492
# File 'lib/bureaucrat/widgets.rb', line 490

def renderer
  RadioFieldRenderer
end