class CustomAttributes::ListFieldType
Public Instance Methods
possible_custom_value_options(custom_value)
click to toggle source
# File lib/custom_attributes/field_types/list_field_type.rb, line 5 def possible_custom_value_options(custom_value) options = possible_values_options(custom_value.custom_field) missing = [custom_value.value].flatten.reject(&:blank?) - options if missing.any? options += missing end options end
possible_values_options(custom_field, object=nil)
click to toggle source
# File lib/custom_attributes/field_types/list_field_type.rb, line 14 def possible_values_options(custom_field, object=nil) custom_field.possible_values end
validate_custom_field(custom_field)
click to toggle source
# File lib/custom_attributes/field_types/list_field_type.rb, line 18 def validate_custom_field(custom_field) errors = [] errors << [:possible_values, :blank] if custom_field.possible_values.blank? errors << [:possible_values, :invalid] unless custom_field.possible_values.is_a? Array errors end
validate_custom_value(custom_value)
click to toggle source
# File lib/custom_attributes/field_types/list_field_type.rb, line 25 def validate_custom_value(custom_value) values = Array.wrap(custom_value.value).reject {|value| value.to_s == ''} invalid_values = values - Array.wrap(custom_value.value_was) - custom_value.custom_field.possible_values if invalid_values.any? [::I18n.t('activerecord.errors.messages.inclusion')] else [] end end