mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Fix for validates :timeliness form to add attributes to plugin set
This commit is contained in:
@@ -15,12 +15,7 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def timeliness_validation_for(attr_names, type)
|
||||
options = _merge_attributes(attr_names).merge(:type => type)
|
||||
if respond_to?(:timeliness_validated_attributes)
|
||||
self.timeliness_validated_attributes ||= []
|
||||
self.timeliness_validated_attributes += (attr_names - self.timeliness_validated_attributes)
|
||||
end
|
||||
validates_with TimelinessValidator, options
|
||||
validates_with TimelinessValidator, _merge_attributes(attr_names).merge(:type => type)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ module ValidatesTimeliness
|
||||
def timeliness_attribute_type(attr_name)
|
||||
{
|
||||
Date => :date,
|
||||
Time => :datetime,
|
||||
Time => :time,
|
||||
DateTime => :datetime
|
||||
}[fields[attr_name.to_s].type] || :datetime
|
||||
end
|
||||
|
||||
@@ -39,6 +39,13 @@ module ValidatesTimeliness
|
||||
super
|
||||
end
|
||||
|
||||
def setup(model)
|
||||
if model.respond_to?(:timeliness_validated_attributes)
|
||||
model.timeliness_validated_attributes ||= []
|
||||
model.timeliness_validated_attributes |= @attributes
|
||||
end
|
||||
end
|
||||
|
||||
def validate_each(record, attr_name, value)
|
||||
raw_value = attribute_raw_value(record, attr_name) || value
|
||||
return if (@allow_nil && raw_value.nil?) || (@allow_blank && raw_value.blank?)
|
||||
|
||||
Reference in New Issue
Block a user