Dynamic validation boundaries #281

Closed
ares opened this Issue Feb 20, 2012 · 2 comments

Projects

None yet

2 participants

@ares
Contributor
ares commented Feb 20, 2012

Hi,

I found one thing I'm missing. Imagine you have this validation in Value model that is limited by it's Boundary setting (another model)

validates :value, :numericality => { :less_than => Proc.new {|o| o.boundary.maximum } }

This Proc works great in rails but CSV probably expect just number in here. CSV should eval this Proc before using it. I think adding this won't be hard but I couldn't trace a right place to edit.

@ares ares added a commit to ares/client_side_validations that referenced this issue Feb 22, 2012
@ares ares Enable Proc as a validation parameter refs #281 cd46d9f
@ares ares added a commit to ares/client_side_validations that referenced this issue Feb 22, 2012
@ares ares Enable Proc as a validation parameter refs #281 f3eb37d
Contributor
ares commented Feb 22, 2012

I made two identical patches/commits, one is based on master (pull request made for this) and second one is based on latest tagged version. I'd be happy to provide also test for this but I was not able to run them on my linux box. Maybe you could provide some info on wiki how one should run tests. I'm getting a lot of errors (not failed test) running rake test (and rake test:ruby).

This patch basically calls a Proc instance if specified in validation hash. I think it greatly extends functionality as I wrote in example in first comment.

@ares ares added a commit to ares/client_side_validations that referenced this issue Mar 26, 2012
@ares ares Enable Proc as a validation parameter refs #281
This allows ClientSideValidations to respect Proc parameters
as ActiveModel does.

I added also tests for new functionality. Missed only lenght test
because rails does not allow Procs for LengthValidator
b8b98d6
Contributor

Hey @ares I'm going to close this issue in favor of #284

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment