Class: Bureaucrat::Fields::MultipleChoiceField

Inherits:
ChoiceField show all
Defined in:
lib/bureaucrat/fields.rb

Overview

TODO: tests

Constant Summary

Constants included from Validation::Validators

Validation::Validators::EMAIL_RE

Instance Attribute Summary

Attributes inherited from Field

#error_messages, #help_text, #hidden_widget, #initial, #label, #required, #show_hidden_initial, #widget

Instance Method Summary collapse

Methods inherited from ChoiceField

#choices, #choices=, #initialize, #valid_value?

Methods inherited from Field

hidden_widget, inherited, #initialize, #initialize_copy, set_error, #validating, widget, #widget_attrs

Methods included from Validation::Converters

to_big_decimal, to_bool, to_float, to_integer

Methods included from Validation::Validates

fail_with

Methods included from Validation::Validators

empty_value?, has_max_decimal_places, has_max_digits, has_max_length, has_max_whole_digits, has_min_length, included_in, is_array, is_email, is_not_greater_than, is_not_lesser_than, is_present, is_true, matches_regex, not_empty

Constructor Details

This class inherits a constructor from Bureaucrat::Fields::ChoiceField

Instance Method Details

#clean(value) ⇒ Object



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/bureaucrat/fields.rb', line 438

def clean(value)
  validating do
      is_present(value) if @required
      return [] if ! @required && ! value || value.empty?
      is_array(value)
      not_empty(value) if @required

      new_value = value.map(&:to_s)
      new_value.each do |val|
        fail_with(:invalid_choice, :value => val) unless valid_value?(val)
      end
    end

  new_value
end