Class: Bureaucrat::Widgets::MultipleHiddenInput

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

Constant Summary

Constants included from Utils

Utils::ESCAPES

Instance Attribute Summary collapse

Attributes inherited from Widget

#attrs

Instance Method Summary collapse

Methods inherited from Input

inherited

Methods inherited from Widget

#build_attrs, #has_changed?, #hidden?, id_for_label, inherited, #initialize_copy, #media

Methods included from Utils

conditional_escape, escape, flatatt, format_string, make_bool, make_float, mark_safe, pretty_name, security_hash

Constructor Details

#initialize(attrs = nil, choices = []) ⇒ MultipleHiddenInput

Returns a new instance of MultipleHiddenInput.



209
210
211
212
213
# File 'lib/bureaucrat/widgets.rb', line 209

def initialize(attrs=nil, choices=[])
  super(attrs)
  # choices can be any enumerable
  @choices = choices
end

Instance Attribute Details

#choicesObject

Used by choice fields



207
208
209
# File 'lib/bureaucrat/widgets.rb', line 207

def choices
  @choices
end

Instance Method Details

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



215
216
217
218
219
220
221
222
223
# File 'lib/bureaucrat/widgets.rb', line 215

def render(name, value, attrs=nil, choices=[])
  value ||= []
  final_attrs = build_attrs(attrs, :type => self.class.input_type,
                            :name => name)
  mark_safe(value.map do |v|
              rattrs = {:value => v.to_s}.merge(final_attrs)
              "<input#{flatatt(rattrs)} />"
            end.join("\n"))
end

#value_from_datahash(data, files, name) ⇒ Object



225
226
227
228
229
230
231
232
# File 'lib/bureaucrat/widgets.rb', line 225

def value_from_datahash(data, files, name)
  #if data.is_a?(MultiValueDict) || data.is_a?(MergeDict)
  #  data.getlist(name)
  #else
  #  data[name]
  #end
  data[name]
end