yuyang041060120 / ng2-validation

angular2 validation
https://yuyang041060120.github.io/ng2-validation/index.html
MIT License
611 stars 213 forks source link

Support for lazy value validation #47

Closed intellix closed 7 years ago

intellix commented 7 years ago

I've got a minimum age required to register so I'm exposing that date to the view. If you change country then the minimum age required changes, and so the maxDate validation changes.

In order for the view to know a value changed, the date reference needs to change but unfortunately the reference is broken for maxDate validation.

I'm currently getting around this like:

function lazyMaxDateValidator(fn) {
  return function(control) {
    const d = new Date(control.value);
    const then = fn();
    return (d <= new Date(then)) ? null : { maxDate: true };
  }
}

Perhaps it would be good to support both a function and a date with min/maxDate and anything else that takes a reference?