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

Better support for arrays #1

Open
ansman opened this issue Oct 5, 2014 · 3 comments · May be fixed by #124
Open

Better support for arrays #1

ansman opened this issue Oct 5, 2014 · 3 comments · May be fixed by #124
Milestone

Comments

@ansman
Copy link
Owner

ansman commented Oct 5, 2014

This would be very useful for validating input from checkbox for example where you can choose more than one alternative.

The length validator already works with arrays (though the default message is for strings) but perhaps inclusion should (optionally?) support arrays saying that each item in the array must be in the inclusion list.

Another useful thing to validate would be uniqueness of the items in the array to make sure you haven't picked the same item twice.

@ansman ansman added this to the 0.3.0 milestone Oct 5, 2014
@ansman ansman modified the milestones: Next, 1.0 Oct 10, 2015
@am17torres
Copy link

This would be particularly useful for me at the moment. I am trying to figure out the best way to validate all child objects inside an array.

I have an object that looks something like this:

{
  jobs:[
    {
      key: value
    },
    {
      key: value,
      anotherKey: 'anotherValue'
    },
    {
      invalidKey: false
    }
  ]
}

Just brainstorming syntax I was figuring something like this...

jobs: {
  presence: true,
  length: {
    minimum: 1,
    maximum: 5
  }
  // maybe this only supports arrays?
  each: {
    key: {
      presence: {
        message: 'is required!'
      }
    },
    anotherKey: {
      datetime: true
    }
  }
}

Also clean attributes would have to be updated to toss invalidKey from the 3rd item in the job object as it is not defined in the constraints under each.

Thoughts?

jpbufe3 pushed a commit to jpbufe3/validate.js that referenced this issue Apr 3, 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 ansman#1
jpbufe3 pushed a commit to jpbufe3/validate.js that referenced this issue 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 ansman#1
jpbufe3 added a commit to jpbufe3/validate.js that referenced this issue 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 ansman#1
@ansman ansman mentioned this issue Jul 25, 2016
@ansman ansman modified the milestones: 0.11.0, Next Nov 5, 2016
@ansman ansman modified the milestones: 0.12.0, Next Oct 17, 2017
@activebiz
Copy link

Any idea when this is going out? Must say this is much needed feature.

@paulevmo
Copy link

You could do something like this: https://stackoverflow.com/a/51406790/2847302

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

Successfully merging a pull request may close this issue.

4 participants