MCPcopy Create free account
hub / github.com/angular/angular / cleanUpValidators

Function cleanUpValidators

packages/forms/src/directives/shared.ts:225–264  ·  view source on GitHub ↗
(
  control: AbstractControl | null,
  dir: AbstractControlDirective,
)

Source from the content-addressed store, hash-verified

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

Callers 4

onDestroyFunction · 0.90
_updateValidatorsFunction · 0.90
cleanUpControlFunction · 0.85
cleanUpFormContainerFunction · 0.85

Calls 7

getControlValidatorsFunction · 0.90
isArrayMethod · 0.80
setValidatorsMethod · 0.80
setAsyncValidatorsMethod · 0.80
filterMethod · 0.45

Tested by

no test coverage detected