@ -32,9 +32,8 @@ class CustomField < ActiveRecord::Base
has_many :custom_values , dependent : :delete_all
acts_as_list scope : 'type = \'#{self.class}\''
translates :name ,
:default_value ,
:possible_values
translates :name , fallbacks_for_empty_translations : false
translates :default_value , :possible_values
accepts_nested_attributes_for :translations ,
allow_destroy : true ,
@ -57,6 +56,8 @@ class CustomField < ActiveRecord::Base
validates_presence_of :field_format
validates :name , presence : true , length : { maximum : 30 }
validate :uniqueness_of_name_with_scope
def uniqueness_of_name_with_scope
@ -73,8 +74,6 @@ class CustomField < ActiveRecord::Base
validate :validate_default_value_in_translations
validate :validate_name
validates :min_length , numericality : { only_integer : true , greater_than_or_equal_to : 0 }
validates :max_length , numericality : { only_integer : true , greater_than_or_equal_to : 0 }
validates :min_length , numericality : { less_than_or_equal_to : :max_length , message : :smaller_than_or_equal_to_max_length } , unless : Proc . new { | cf | cf . max_length . blank? }
@ -117,26 +116,6 @@ class CustomField < ActiveRecord::Base
self . is_required = required_field
end
# check presence of name and check the length of name value
def validate_name
if translations . empty?
errors . add ( :name , :blank ) if name . nil?
else
fallback_name = translations . find { | el | ! el . name . nil? }
translations . each do | translation |
if translation . name . nil? && fallback_name . nil?
errors . add ( :name , :blank )
else
if ( translation . name . nil? && fallback_name . name . length > 30 ) || ( ! translation . name . nil? && translation . name . length > 30 )
errors . add ( :name , I18n . t ( 'activerecord.errors.messages.wrong_length' , count : 30 ) )
end
translation . name = fallback_name . name if translation . name . nil?
end
end
end
end
def possible_values_options ( obj = nil )
case field_format
when 'user' , 'version'