Better support for arrays
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.
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?
Any idea when this is going out? Must say this is much needed feature.
You could do something like this: https://stackoverflow.com/a/51406790/2847302