Undistraction / folktale-validations

Validators and related utils for working with Folktale's Validation.
MIT License
7 stars 3 forks source link

Automatically Validate Children With validateIsArray #12

Open Undistraction opened 6 years ago

Undistraction commented 6 years ago

Currently a validator needs to be added to fields with a children attribute to make the constraints object valid. This enables the flexibility of using validateIsNonEmpty or a custom validator that checks for a minimum or maximum number of values, however it would be nice to provide a default of validateIsArray if the validator is missing.

This will involve two steps:

  1. Validation

This will mean amending the constraints validation to allow an object to pass if the following conditions are met:

Currently the validation is of whitelisted keys which will fail if no validator field is present.

A more specialised validator is needed, that checks the other fields for a children field if no validator field is present.

  1. Defaults

The default value of 'validatorwill need to be set to 'validateIsArray. This is a little clunky, but will work short-term. Longer term, the application of defaultValue should probably work with functions that can decide on a default value based on the object as a whole.