LuccaSA / lucca-front

documentation
https://prisme.lucca.io
MIT License
40 stars 4 forks source link

bug(lu-number-input): `min` & `max` validator initlialization race condition #3235

Open Supamiu opened 5 days ago

Supamiu commented 5 days ago

When using a lu-number-input with min and/or max input, they are forwarded to the inner input type="number" which triggers Angular's MinValidator or the corresponding for max.

This produces a changes call (https://github.com/angular/angular/blob/1bdc3f1aaef5a7e8bee25447aa8619872cf0eb96/packages/forms/src/directives/validators.ts#L158) which doesn't trigger a new validation cycle because it happens before registerOnValidatorChange which is declared few lines below.

This means that if a value is already present when adding the field, it won't be checked by the newly added validators, resulting in form being marked as valid despite being invalid.

Further investigation is needed but a quick and dirty fix on the consumer end is to add a new patchValue call after initializing the form.