Dynamic Constrants in Simple Schema

Hi, I’m using @aldeed 's awesome autoform/simple schema and have run into a problem. For a given schema, some of the fields have both complex validation requirements and depending on the circumstances/context the min/max are variable.

The problem I’m having is that the ‘custom’ attribute for a field passes in a wealth of info/hooks, etc so I’m able to do my validation with no problem. However in my custom function, I might say determine that the field is invalid due to a ‘minNumber’ violation, so far so good. But, as I mentioned, I need to dynamically set the ‘min’. Setting say ‘this.definition.min’ inside the custom function, doesn’t seem to work. And if I use a function for ‘min’, its ‘this’ is very limited, and only has information about the field itself. This doesn’t give me enough info with which to compute the min dynamically.

The other issue is that while you can create a custom validation message, it still depends on you returning a key to that message from the custom validator as opposed to the message itself. So it’s still hard to say return “Field should be more than 50”, where 50 might vary as I still need to really create a “Field should be more than [min]”, and ‘min’ needs to be set appropriately

Has anyone had a similar issue?

This seems to be a solution. Trying it out right now.