II. For custom validator, if we have defined it in separate const, do we have some way to read value from other form controls somehow? Let's say I wanna validate current control value against another control value from this form. Or in that case we probably should declare custom validator in dyn form host component?
I. Yes, ['range', [1, 5]] will be translated to its corresponding Factory call like fn(1, 5) and for more complex cases an object could be used like ['asyncUniqueEmail', { endpoint: '...', minLength: 4, ... }] and you will receive it in your Factory fn({ endpoint, minLength, ... }) :)
Liked it! Thanks for this!
Have a few questions here:
I. What if I wanna to provide a few params for one validator in array notation?
Will this be correct (range ex.):
options: { validators: ['required', ['range', [1, 5] ] ] },
II. For custom validator, if we have defined it in separate const, do we have some way to read value from other form controls somehow? Let's say I wanna validate current control value against another control value from this form. Or in that case we probably should declare custom validator in dyn form host component?
Important point: before reading this article it's nice to read this article first dev.to/myndpm/a-new-approach-to-ha...
I. Yes,
['range', [1, 5]]
will be translated to its corresponding Factory call likefn(1, 5)
and for more complex cases an object could be used like['asyncUniqueEmail', { endpoint: '...', minLength: 4, ... }]
and you will receive it in your Factoryfn({ endpoint, minLength, ... })
:)II. Let's try to implement that Validator with
Matchers
for the next chapter of this series: github.com/myndpm/open-source/issu...Thank you for your feedback! :D