Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

feat(validators): Add validator for each object in an array #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpbufe3
Copy link

@jpbufe3 jpbufe3 commented Apr 26, 2016

Added a new validator, each, which applies a validation function
provided in the options to each of the objects in the array being
validated.

Closes #1

@jpbufe3
Copy link
Author

jpbufe3 commented Apr 26, 2016

@ansman If options.validator is not a function, I'm currently allowing that behavior without returning an error. Let me know if you think I should change that and I can create separate error messages for the object not being an array and the validator not being a function.

Added a new validator, `each`, which applies a validation function
provided in the options to each of the objects in the array being
validated.

Closes ansman#1
@michaek
Copy link

michaek commented Jun 13, 2016

@ansman This seems like a valuable addition. What do you think?

@ansman
Copy link
Owner

ansman commented Jun 18, 2016

Hmm, I'd rather see that you specify a constraint for each element

@michaek
Copy link

michaek commented Jun 20, 2016

I think that's feasible, and I agree that it makes the constraint syntax less complex.

However, the array case is slightly different from the object case: in an object, we know what the keys are that we want to validate, and we can define constraints for these keys one time (in a schema definition, for example). For an array, we would need to programmatically add constraints to the array of data we receive before performing validation. Like I said, it's feasible, but it's a different pattern, and the each syntax would allow us to follow the schema definition pattern for arrays.

Thanks!

@andrefox333
Copy link

Any updates to this PR? We'll we see this feature added soon? We could totally use this feature in our project. Thanks :)

@ansman ansman added this to the Next milestone Nov 5, 2016
@thinklinux
Copy link

Seems good 👍 Any progress or ETA on this?

@danny-andrews
Copy link

Ping. This looks awesome!

@dreamalligator
Copy link

is this or #184 preferred? would love to have this feature!

@deathweaselx86
Copy link

What's going on with this?

@ansman ansman modified the milestones: 0.12.0, Next Oct 17, 2017
@recidive
Copy link

recidive commented Mar 7, 2018

Hello folks, any update on this nice feature?

@jpbufe3
Copy link
Author

jpbufe3 commented Mar 7, 2018

@ansman - are you going to accept this? if so I'll resolve the conflicts

@activebiz
Copy link

Any update on this? Cant wait to get this one!

@jpbufe3
Copy link
Author

jpbufe3 commented Jul 6, 2018

It looks like @ansman is no longer monitoring or maintaining this repository. I'm not sure if he wants to add some maintainers to this project or if someone should fork and continue development from there

@deathweaselx86
Copy link

deathweaselx86 commented Jul 6, 2018 via email

@vpillinger
Copy link

@ansman If you no longer desire to maintain this project I am willing to take it over. Whether by forking or by via contributing to this repo. There is a surprising lack of pure-javascript validation libraries that can be easily used with React/Angular or other front-end libraries.

@nebulousdog I would argue that this implementation is preferred over #184 because it returns an array with the same number of elements as the original data. This mirrors the way the rest of the library works much better and makes it easier to work with by keeping the same format between the original data and the error messages. Additionally, this PR has unit testing while the other does not.

@dreamalligator
Copy link

sounds good @vpillinger 👍

@jpbufe3
Copy link
Author

jpbufe3 commented Feb 28, 2019

@vpillinger - if you end up forking, let me know and I can fix the merge conflicts and put this PR up against your repo

@ansman ansman force-pushed the master branch 4 times, most recently from feffe94 to 40e06a1 Compare June 15, 2019 17:55
@guilherme90
Copy link

Hello, this PR is very important for the validator. Do we have any news about that? Won't you join the master branch?

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

Successfully merging this pull request may close these issues.

Better support for arrays