Class: Bureaucrat::Widgets::RadioInput
- Inherits:
-
Object
- Object
- Bureaucrat::Widgets::RadioInput
show all
- Includes:
- Utils
- Defined in:
- lib/bureaucrat/widgets.rb
Constant Summary
Constants included
from Utils
Utils::ESCAPES
Instance Method Summary
collapse
Methods included from Utils
#blank_value?, #conditional_escape, #escape, #flatatt, #format_string, #make_bool, #make_float, #mark_safe, #pretty_name
Constructor Details
#initialize(name, value, attrs, choice, index) ⇒ RadioInput
Returns a new instance of RadioInput.
425
426
427
428
429
430
431
432
|
# File 'lib/bureaucrat/widgets.rb', line 425
def initialize(name, value, attrs, choice, index)
@name = name
@value = value
@attrs = attrs
@choice_value = choice[0].to_s
@choice_label = choice[1].to_s
@index = index
end
|
Instance Method Details
#checked? ⇒ Boolean
440
441
442
|
# File 'lib/bureaucrat/widgets.rb', line 440
def checked?
@value == @choice_value
end
|
#tag ⇒ Object
444
445
446
447
448
449
450
|
# File 'lib/bureaucrat/widgets.rb', line 444
def tag
@attrs[:id] = "#{@attrs[:id]}_#{@index}" if @attrs.include?(:id)
final_attrs = @attrs.merge(type: 'radio', name: @name,
value: @choice_value)
final_attrs[:checked] = 'checked' if checked?
mark_safe("<input#{flatatt(final_attrs)} />")
end
|
#to_s ⇒ Object
434
435
436
437
438
|
# File 'lib/bureaucrat/widgets.rb', line 434
def to_s
label_for = @attrs.include?(:id) ? " for=\"#{@attrs[:id]}_#{@index}\"" : ''
choice_label = conditional_escape(@choice_label.to_s)
mark_safe("<label#{label_for}>#{tag} #{choice_label}</label>")
end
|