Class: Bureaucrat::Widgets::MultipleHiddenInput
- Inherits:
-
HiddenInput
- Object
- Widget
- Input
- HiddenInput
- Bureaucrat::Widgets::MultipleHiddenInput
- Defined in:
- lib/bureaucrat/widgets.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary collapse
-
#choices ⇒ Object
Used by choice fields.
Attributes inherited from Widget
Instance Method Summary collapse
-
#initialize(attrs = nil, choices = []) ⇒ MultipleHiddenInput
constructor
A new instance of MultipleHiddenInput.
- #render(name, value, attrs = nil, choices = []) ⇒ Object
Methods inherited from HiddenInput
Methods inherited from Input
Methods inherited from Widget
#build_attrs, #has_changed?, #hidden?, id_for_label, #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(attrs = nil, choices = []) ⇒ MultipleHiddenInput
Returns a new instance of MultipleHiddenInput.
109 110 111 112 113 |
# File 'lib/bureaucrat/widgets.rb', line 109 def initialize(attrs=nil, choices=[]) super(attrs) # choices can be any enumerable @choices = choices end |
Instance Attribute Details
#choices ⇒ Object
Used by choice fields
107 108 109 |
# File 'lib/bureaucrat/widgets.rb', line 107 def choices @choices end |
Instance Method Details
#render(name, value, attrs = nil, choices = []) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/bureaucrat/widgets.rb', line 115 def render(name, value, attrs=nil, choices=[]) value ||= [] final_attrs = build_attrs(attrs, type: input_type.to_s, name: "#{name}[]") id = final_attrs[:id] inputs = [] value.each.with_index do |v, i| input_attrs = final_attrs.merge(value: v.to_s) if id input_attrs[:id] = "#{id}_#{i}" end inputs << "<input#{flatatt(input_attrs)} />" end mark_safe(inputs.join("\n")) end |