Class: Bureaucrat::Widgets::SelectMultiple

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

Direct Known Subclasses

CheckboxSelectMultiple

Constant Summary

Constants included from Utils

Utils::ESCAPES

Instance Attribute Summary

Attributes inherited from Select

#choices

Attributes inherited from Widget

#attrs, #is_required

Instance Method Summary collapse

Methods inherited from Select

#initialize, #render_option, #render_options

Methods inherited from Widget

#build_attrs, #hidden?, id_for_label, #initialize, #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

This class inherits a constructor from Bureaucrat::Widgets::Select

Instance Method Details

#has_changed?(initial, data) ⇒ Boolean

Returns:

  • (Boolean)


410
411
412
413
414
415
416
417
418
419
# File 'lib/bureaucrat/widgets.rb', line 410

def has_changed?(initial, data)
  initial = [] if initial.nil?
  data = [] if data.nil?

  if initial.length != data.length
    return true
  end

  Set.new(initial.map(&:to_s)) != Set.new(data.map(&:to_s))
end

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



400
401
402
403
404
405
406
407
408
# File 'lib/bureaucrat/widgets.rb', line 400

def render(name, value, attrs=nil, choices=[])
  value = [] if value.nil?
  final_attrs = build_attrs(attrs, name: "#{name}[]")
  output = ["<select multiple=\"multiple\"#{flatatt(final_attrs)}>"]
  options = render_options(choices, value)
  output << options if options && !options.empty?
  output << '</select>'
  mark_safe(output.join("\n"))
end