Comments (24)
If you don't validate the date does the text_field version work?
from validates_timeliness.
Yes. Removing the date validation results in the text_field being populated
with the existing value, if it exists.
On Sep 2, 2011 5:09 AM, "adzap" <
[email protected]>
wrote:
If you don't validate the date does the text_field version work?
Reply to this email directly or view it on GitHub:
from validates_timeliness.
A failing test for this would be great help.
from validates_timeliness.
+1 for this issue, not really sure how to test this but I'll give it a stab in the next day or two.
from validates_timeliness.
I have had a play and have seen the bug. It seems to only occur when the config.extend_orms = [:active_record] is set. Commenting it works ok.
from validates_timeliness.
I've found the issue. It's to do with the before_type_cast implementation not returning the initial attribute value. Will work on a fix.
On 20/09/2011, at 9:12 AM, [email protected] wrote:
- 1 for this issue, not really sure how to test this but I'll give it a stab in the next day or two.
Reply to this email directly or view it on GitHub:
#52 (comment)
from validates_timeliness.
v3.0.7 should fix this.
from validates_timeliness.
I'm using Rails 3.1 and I don't see how this fix helps. Here is an example,
model.my_date = 'foo'
model.my_date # --> nil
model.my_date_before_type_cast # --> also nil!
Looking at the code, it seems validates_timeliness defines my_date= and stores the original value in @timelines_cache. In validates_timeliness 3.0.6, this value was then returned by validates timeliness' version of _before_type_cast. In 3.0.7, Rails' version of _before_type_cast is used which doesn't know anything about @timeliness_cache ... so it obviously returns nil.
from validates_timeliness.
Are you saying you are seeing the behaviour of your example using the current version of the plugin with Rails 3.1.0?
from validates_timeliness.
Yes. I am updating an app to from Rails 3.0 to Rails 3.1 and using validates_timeliness 3.0.7.
The problem occurs with 3.0.6 as well which is puzzling because I thought 3.0.6 defined its own before_type_cast method. Perhaps I'm missing something with how before_type_cast works in Rails 3.1.
from validates_timeliness.
Are you using ActiveRecord?
The before_type_cast method is only defined by the plugin if the a true value is passed to define_timeliness_before_type_cast method. The AR shim checks the version and passes a false if AR version is 3.1.0 or above. Therefore default AR before_type_cast implementation should be being used.
from validates_timeliness.
This issue still seems to exist when enabling the parser_plugin in rails 3.1.3:
ValidatesTimeliness.setup do |config|
config.use_plugin_parser = true
end
model.my_date = 'foo'
model.my_date # --> nil
model.my_date_before_type_cast # --> nil!
When I turn off the parser_plugin it works as expected:
model.my_date = 'foo'
model.my_date # --> nil
model.my_date_before_type_cast # --> "foo"
from validates_timeliness.
Ok, I see the problem. I will work on a fix.
from validates_timeliness.
Thanks!
from validates_timeliness.
Thanks, good luck
from validates_timeliness.
I've pushed a fix which is a bit messy but it should work. Can you verify please. No gem update yet.
from validates_timeliness.
Unfortunately it doesn't work here, the whole parser-plugin seems to be disabled now:
version 3.0.8:
model.my_date = 'foo'
=> "foo"
model.valid?
=> false
model.errors[:my_date]
=> ["is not a valid date"]
ValidatesTimeliness.use_plugin_parser
=> true
New version from github:
model.my_date = 'foo'
=> "foo"
model.valid?
=> false # other errors in the model
model.errors[:my_date]
=> []
ValidatesTimeliness.use_plugin_parser
=> true
from validates_timeliness.
This would be a symptom of the attribute value caching not working, rather than the parser. But nonetheless, it is a problem I will look into.
from validates_timeliness.
I've released a new gem version. Please verify if it fixes this issue.
from validates_timeliness.
Hi,
I'm afraid this still doesn't resolve the issue. I'm using rails 3.2.0 and validates_timeliness 3.0.9. The output is the same again.
model.my_date = 'foo'
=> "foo"
model.valid?
=> false # other errors in the model
model.errors[:my_date]
=> []
ValidatesTimeliness.use_plugin_parser
=> true
In my model i have the line:
validates_date :my_date, allow_blank: true
If I change line 7 of active_record.rb to true
. Everything seems to work as expected
# In active_record.rb of validates_timeliness 3.0.9
def self.use_plugin_cache?
true
end
model.my_date = 'foo'
=> "foo"
model.valid?
=> false
model.errors[:my_date]
=> ["is not a valid date"]
model.my_date
=> nil
model.my_date_before_type_cast
=> "foo"
ValidatesTimeliness.use_plugin_parser
=> true
I hope this helps with the issue. Good luck
from validates_timeliness.
Yes, it does thanks.
On 27/03/2012, at 8:08 PM, Stephan van [email protected] wrote:
Hi,
I'm afraid this still doesn't resolve the issue. I'm using rails 3.2.0 and validates_timeliness 3.0.9. The output is the same again.model.my_date = 'foo' => "foo" model.valid? => false # other errors in the model model.errors[:my_date] => [] ValidatesTimeliness.use_plugin_parser => trueIn my model i have the line:
validates_date :my_date, allow_blank: true
If I change line 7 of active_record.rb to
true
. Everything seems to work as expected# In active_record.rb of validates_timeliness 3.0.9 def self.use_plugin_cache? true endmodel.my_date = 'foo' => "foo" model.valid? => false model.errors[:my_date] => ["is not a valid date"] model.my_date => nil model.my_date_before_type_cast => "foo" ValidatesTimeliness.use_plugin_parser => trueI hope this helps with the issue. Good luck
Reply to this email directly or view it on GitHub:
#52 (comment)
from validates_timeliness.
I have pushed a new release to fix this. Please give it a try.
from validates_timeliness.
Hi,
The fix seems to work for dates, but there are still some problems with times.
# entering an invalid time works as expected
model.my_time = '12:66'
=> "12:66"
model.my_time
=> nil
model.valid?
=> false
model.errors[:my_time]
=> ["is not a valid time"]
# entering an other string; doesn't work properly
model.my_time = 'foo'
=> "foo"
model.my_time
=> 2000-01-01 00:00:00 UTC
model.valid?
=> false # other errors in the model
model.errors[:my_time]
=> []
from validates_timeliness.
I found the issue for the invalid time being returned as a time object. It is an ActiveRecord bug in dummy_string_to_time. I will close this issue and open a new one, to see I can do a work around. Also will fix the bug in AR hopefully.
from validates_timeliness.
Related Issues (20)
- Check time_zone_aware_types HOT 3
- Plans to release a official 6.x version HOT 3
- `add_error` call with wrong number of arguments HOT 2
- Issue on engine test load HOT 2
- ArgumentError: wrong number of arguments (given 3, expected 1..2) on records.error.add HOT 8
- Locale for Vietnamese HOT 2
- Rails 7 Deprecation Warnings HOT 6
- Rails 7 dependency - activemodel HOT 4
- Please support Rails 7 then cut a new version HOT 1
- Additional maintainer needed HOT 2
- Support for Rails 7 HOT 4
- Is there any way that I can make sure that ranges are exclusive?
- Handle when the passed value is not a Date value. when it's a Numeric
- Comparison to ComparisonValidator HOT 3
- Format Validation only works for yyyy-mm-dd
- Support for Rails 7.1
- Friendly request for a new release with Rails 7.1 support ;) HOT 1
- Please add me to maintainers
- Does not work on rails-edge
- Please release a new version for Rails 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validates_timeliness.