summaryrefslogtreecommitdiffstats
path: root/app/models/custom_value.rb
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/custom_value.rb
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/custom_value.rb')
-rw-r--r--app/models/custom_value.rb11
1 files changed, 6 insertions, 5 deletions
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
-