( control: AbstractControl | null, dir: AbstractControlDirective, )
| 222 | * @returns true if a control was updated as a result of this action. |
| 223 | */ |
| 224 | export function cleanUpValidators( |
| 225 | control: AbstractControl | null, |
| 226 | dir: AbstractControlDirective, |
| 227 | ): boolean { |
| 228 | let isControlUpdated = false; |
| 229 | if (control !== null) { |
| 230 | if (dir.validator !== null) { |
| 231 | const validators = getControlValidators(control); |
| 232 | if (Array.isArray(validators) && validators.length > 0) { |
| 233 | // Filter out directive validator function. |
| 234 | const updatedValidators = validators.filter((validator) => validator !== dir.validator); |
| 235 | if (updatedValidators.length !== validators.length) { |
| 236 | isControlUpdated = true; |
| 237 | control.setValidators(updatedValidators); |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if (dir.asyncValidator !== null) { |
| 243 | const asyncValidators = getControlAsyncValidators(control); |
| 244 | if (Array.isArray(asyncValidators) && asyncValidators.length > 0) { |
| 245 | // Filter out directive async validator function. |
| 246 | const updatedAsyncValidators = asyncValidators.filter( |
| 247 | (asyncValidator) => asyncValidator !== dir.asyncValidator, |
| 248 | ); |
| 249 | if (updatedAsyncValidators.length !== asyncValidators.length) { |
| 250 | isControlUpdated = true; |
| 251 | control.setAsyncValidators(updatedAsyncValidators); |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | // Clear onValidatorChange callbacks by providing a noop function. |
| 258 | const noop = () => {}; |
| 259 | registerOnValidatorChange<ValidatorFn>(dir._rawValidators, noop); |
| 260 | registerOnValidatorChange<AsyncValidatorFn>(dir._rawAsyncValidators, noop); |
| 261 | |
| 262 | return isControlUpdated; |
| 263 | } |
| 264 | |
| 265 | function setUpViewChangePipeline(control: FormControl, dir: NgControl): void { |
| 266 | dir.valueAccessor!.registerOnChange((newValue: any) => { |
no test coverage detected
searching dependent graphs…