Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
Currently i have noticed that only required() validator is optional using {when: () => {}} option.
Imagine situation when you have form for model.
/**
* Interface describing editation data of marker arg
*/
export interface MarkerArgEdit
{
/**
* Code of marker
*/
kod: string|undefined|null;
/**
* Value of marker
*/
hodnota: string|number|undefined|null;
}
You have control for kod, which is select (combo box), according selected value of kod you will change type of input for hodnota. It can be number input, string input or select (combo box) with available string values.
This means that validation for hodnota can differ according selected value in kod. So it means that i would like to have schema like this:
min(path.hodnota, () => some logic, {when: () => this.kodObj().type == 'INT'});
max(path.hodnota, () => some logic, {when: () => this.kodObj().type == 'INT'});
pattern(path.hodnota, () => some logic, {when: () => this.kodObj().type == 'STRING'});
This is currently impossible since only required validator can be optional.
There is also problem with typings as you can see here #63789, so maybe some casting (type narrowing) would be also nice, because min allows only number and pattern allows only string but hodnota is string|number.
Proposed solution
Move {when?: NoInfer<LogicFn<TValue, boolean, TPathKind>} into BaseValidatorConfig so all validators can be optional.
Alternatives considered
Currently no other alternative comes into my mind.
Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
Currently i have noticed that only
required()validator is optional using {when: () => {}} option.Imagine situation when you have form for model.
You have control for
kod, which is select (combo box), according selected value ofkodyou will change type of input forhodnota. It can be number input, string input or select (combo box) with available string values.This means that validation for
hodnotacan differ according selected value inkod. So it means that i would like to have schema like this:This is currently impossible since only
requiredvalidator can be optional.There is also problem with typings as you can see here #63789, so maybe some casting (type narrowing) would be also nice, because
minallows onlynumberandpatternallows onlystringbut hodnota isstring|number.Proposed solution
Move
{when?: NoInfer<LogicFn<TValue, boolean, TPathKind>}intoBaseValidatorConfigso all validators can be optional.Alternatives considered
Currently no other alternative comes into my mind.