Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validators composing #2

Open
alolis opened this issue Apr 18, 2013 · 3 comments
Open

Validators composing #2

alolis opened this issue Apr 18, 2013 · 3 comments
Milestone

Comments

@alolis
Copy link

alolis commented Apr 18, 2013

First of all, I wanna say that the author has done really good work with metis :) It really solved a lot of my issues.

I do have one question though. I have two validators which they are using the same validation rule and I am wondering if I can make the composition like this:

(defvalidator :limit-validator
  [:limit {:only-integer true}])

(defvalidator :items-validator
  [:limit :limit-validator]
  [:my-field :presence])

(defvalidator :another-validator
  [:limit :limit-validator]
  [:another-field :presence]) 

I know the above does not work, I am just trying to explain what am I trying to accomplish :)

@mylesmegyesi
Copy link
Owner

I've been struggling with the same problem myself. I've been considering how to solve this problem in the next version of metis, but there is no built in way yet. For the time being, one idea is:

(def limit-validations [:numericality {:only-integer true}])

(defvalidator :items-validator
  [:limit limit-validations]
  [:my-field :presence])

(defvalidator :another-validator
  [:limit limit-validations]
  [:another-field :presence]

What do you think?

@alolis
Copy link
Author

alolis commented Apr 18, 2013

It's not a bad work around if the shared validator is not used as a standalone validator which it happens to be the case I am dealing with. It will definitely be nice to see a complete solution to a future version of metis :)

In general though I must admit that you've tackled the problem of input validation pretty well :)

@mylesmegyesi
Copy link
Owner

Thank you! Expect to see a solution in the next version!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants