max-validator icon indicating copy to clipboard operation
max-validator copied to clipboard

Document how to validate nested objects

Open boosh opened this issue 3 years ago • 1 comments

Hi, this library looks great. Does it support validating nested objects? E.g. how could I write a schema to validate the object below?

    {
        name: "",
        about: "",
        location: {
          city: "",
          country: "",
          lat: 0,
          lng: 0
        }
    },

I know I can do this:

  location: {
    required: true,
    object: true,
    customRule: function (location) {
      return (location.city.length > 0) ? true : "Please select a location"
    }
  },

But is there a way of embedding validation rules for city, country, lat, lng in the schema directly?

boosh avatar May 21 '21 02:05 boosh