8000 [Validator] what about to have MinCount and MaxCount validators · Issue #2674 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Validator] what about to have MinCount and MaxCount validators #2674

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

Closed
makasim opened this issue Nov 18, 2011 · 7 comments
Closed

[Validator] what about to have MinCount and MaxCount validators #2674

makasim opened this issue Nov 18, 2011 · 7 comments
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) Validator

Comments

@makasim
Copy link
Contributor
makasim commented Nov 18, 2011

Let's say we have a bloger which can assign from one to five tags to his blog. While submiting the server should count tags and check whether the collection in the allowed range. It can be done with Choice validator and min and max options. But in this case we have such problems:

  • It should fetch all tags from db to check that choices are valid,
  • Very hard to define callback in case of using $repository->findAll()

From another side we have Min\Max and MinLength\MaxLength validators but they very restrictive (the first takes only integers and second one only strings)

So I am thinking of moving count validation rules from Choice to a new validators called MinCount and MaxCount

BTW I can do a PR if you find it useful.

@hlecorche
Copy link
Contributor

I agree.
But I don't know what the best solution:

  • Solution 1: Keep min and max options in Choice validator (it's useful) and create new additionals validators called MinCount / MaxCount
  • Solution 2: Move count validation rules from Choice to news validators called MinCount / MaxCount

I have a preference for the first solution.

@makasim
Copy link
Contributor Author
makasim commented Nov 22, 2011

It also could be one valldator Count with two options min and max (instead of MinCount / MaxCount)

@hlecorche
Copy link
Contributor

Yes, I think it's better

@stof
Copy link
Member
stof commented Apr 4, 2012

@bschussek what do you think about it ?

@webmozart
Copy link
Contributor

I would prefer a Size validator that works on arrays.

@webmozart
Copy link
Contributor

Task for the BHD: Change SizeValidator to accept any Countable object.

@vicb
Copy link
Contributor
vicb commented May 20, 2012

fixed by #4149 (and the Size constraint)

@vicb vicb closed this as completed May 20, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Good first issue Ideal for your first contribution! (some Symfony experience may be required) Validator
Projects
None yet
Development

No branches or pull requests

5 participants
0