mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
multiparameter value handler
This commit is contained in:
parent
0f41671b32
commit
4028413631
15
README.rdoc
15
README.rdoc
@ -141,7 +141,7 @@ To turn them on/off:
|
|||||||
|
|
||||||
=== DISPLAY INVALID VALUES IN DATE/TIME SELECT HELPERS:
|
=== DISPLAY INVALID VALUES IN DATE/TIME SELECT HELPERS:
|
||||||
|
|
||||||
The plugin has some extensions to ActionView for allowing invalid
|
The plugin offers an extension for ActionView to allowing invalid
|
||||||
date and time values to be redisplayed to the user as feedback, instead of
|
date and time values to be redisplayed to the user as feedback, instead of
|
||||||
a blank field which happens by default in Rails. Though the date helpers make this a
|
a blank field which happens by default in Rails. Though the date helpers make this a
|
||||||
pretty rare occurrence, given the select dropdowns for each date/time component, but
|
pretty rare occurrence, given the select dropdowns for each date/time component, but
|
||||||
@ -153,6 +153,19 @@ To activate it, put this in an initializer:
|
|||||||
config.enable_date_time_select_extension!
|
config.enable_date_time_select_extension!
|
||||||
|
|
||||||
|
|
||||||
|
=== STRICT DATE/TIME VALUES FOR SELECT HELPERS
|
||||||
|
|
||||||
|
When using date/time select helpers, the component values are handled by ActiveRecord using
|
||||||
|
the Time class to instantiate them into a time value. But this mean that some invalid dates,
|
||||||
|
such as 31st June, are shifted forward and treated as valid. To handle these cases in a strict
|
||||||
|
way you can enable the plugin handler to treat them as invalid dates.
|
||||||
|
|
||||||
|
To activate it, put this in an initializer:
|
||||||
|
|
||||||
|
# in the setup block
|
||||||
|
config.enable_multiparameter_handler!
|
||||||
|
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,4 +10,7 @@ ValidatesTimeliness.setup do |config|
|
|||||||
#
|
#
|
||||||
# Re-display invalid values in date/time selects
|
# Re-display invalid values in date/time selects
|
||||||
# config.enable_date_time_select_extension!
|
# config.enable_date_time_select_extension!
|
||||||
|
#
|
||||||
|
# Handle multiparameter date/time values strictly
|
||||||
|
# config.enable_multiparameter_handler!
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
module ValidatesTimeliness
|
module ValidatesTimeliness
|
||||||
module Extensions
|
module Extensions
|
||||||
autoload :DateTimeSelect, 'validates_timeliness/extensions/date_time_select'
|
autoload :DateTimeSelect, 'validates_timeliness/extensions/date_time_select'
|
||||||
autoload :MultiparameterParser, 'validates_timeliness/extensions/multiparameter_parser'
|
autoload :MultiparameterHandler, 'validates_timeliness/extensions/multiparameter_handler'
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.enable_date_time_select_extension!
|
def self.enable_date_time_select_extension!
|
||||||
::ActionView::Helpers::InstanceTag.send(:include, ValidatesTimeliness::Extensions::DateTimeSelect)
|
::ActionView::Helpers::InstanceTag.send(:include, ValidatesTimeliness::Extensions::DateTimeSelect)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.enable_multiparameter_parser!
|
def self.enable_multiparameter_handler!
|
||||||
::ActiveRecord::Base.send(:include, ValidatesTimeliness::Extensions::MultiparameterParser)
|
::ActiveRecord::Base.send(:include, ValidatesTimeliness::Extensions::MultiparameterHandler)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
module ValidatesTimeliness
|
module ValidatesTimeliness
|
||||||
module Extensions
|
module Extensions
|
||||||
module MultiparameterParser
|
module MultiparameterHandler
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
@ -1,6 +1,6 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ValidatesTimeliness::Extensions::MultiparameterParser do
|
describe ValidatesTimeliness::Extensions::MultiparameterHandler do
|
||||||
let(:employee) { Employee.new }
|
let(:employee) { Employee.new }
|
||||||
|
|
||||||
it 'should return string value for invalid dates' do
|
it 'should return string value for invalid dates' do
|
||||||
Loading…
Reference in New Issue
Block a user