summaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-25 17:38:05 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-25 17:38:05 +0000
commit8610b191ae1a40ff58e90a1225d79c893a49b0d6 (patch)
tree33b98bcfe7d2fd1407602831794f3a05eff588c5 /app/models
parent01ef9f12c816fab283ebc7d96283abd3397c61c8 (diff)
downloadredmine-8610b191ae1a40ff58e90a1225d79c893a49b0d6.tar.gz
redmine-8610b191ae1a40ff58e90a1225d79c893a49b0d6.zip
Added "Float" as a custom field format.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@870 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r--app/models/custom_field.rb7
-rw-r--r--app/models/custom_value.rb11
2 files changed, 10 insertions, 8 deletions
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index 751cc8526..81c8aae06 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -22,9 +22,10 @@ class CustomField < ActiveRecord::Base
FIELD_FORMATS = { "string" => { :name => :label_string, :order => 1 },
"text" => { :name => :label_text, :order => 2 },
"int" => { :name => :label_integer, :order => 3 },
- "list" => { :name => :label_list, :order => 4 },
- "date" => { :name => :label_date, :order => 5 },
- "bool" => { :name => :label_boolean, :order => 6 }
+ "float" => { :name => :label_float, :order => 4 },
+ "list" => { :name => :label_list, :order => 5 },
+ "date" => { :name => :label_date, :order => 6 },
+ "bool" => { :name => :label_boolean, :order => 7 }
}.freeze
validates_presence_of :name, :field_format
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 6cc4d16bf..afe4c1afb 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -26,13 +26,14 @@ protected
errors.add(:value, :activerecord_error_too_short) if custom_field.min_length > 0 and value.length < custom_field.min_length and value.length > 0
errors.add(:value, :activerecord_error_too_long) if custom_field.max_length > 0 and value.length > custom_field.max_length
case custom_field.field_format
- when "int"
- errors.add(:value, :activerecord_error_not_a_number) unless value =~ /^[0-9]*$/
- when "date"
+ when 'int'
+ errors.add(:value, :activerecord_error_not_a_number) unless value.blank? || value =~ /^[+-]?\d+$/
+ when 'float'
+ begin; !value.blank? && Kernel.Float(value); rescue; errors.add(:value, :activerecord_error_invalid) end
+ when 'date'
errors.add(:value, :activerecord_error_not_a_date) unless value =~ /^\d{4}-\d{2}-\d{2}$/ or value.empty?
- when "list"
+ when 'list'
errors.add(:value, :activerecord_error_inclusion) unless custom_field.possible_values.include? value or value.empty?
end
end
end
-