binding icon indicating copy to clipboard operation
binding copied to clipboard

apply validation rules to each item in a Slice

Open woodsaj opened this issue 10 years ago • 1 comments

I would like to be able to apply validation rules to each item in a slice.

eg

type MyStruct struct {
   Id int
   MyNumbers []int `json:"my_numbers" binding:"range(1, 10)"`
}

The following should then fail validation as one of the items in the list is outside of the range.

{
  "id": 1,
  "my_numbers": [1,2,3,4,100]
}

This would require replacing MinSize and MaxSize from being applied to slice lengths, so that rules can instead be used for length of each item in a slice of strings. New rules specific to slice length would then need to be introduced.

woodsaj avatar Sep 09 '15 06:09 woodsaj

https://github.com/macaron-contrib/binding/pull/4 has most of the changes needed to support this.

woodsaj avatar Sep 09 '15 15:09 woodsaj