MCPcopy Index your code
hub / github.com/angular/angular / cleanUpValidators

Function cleanUpValidators

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

Source from the content-addressed store, hash-verified

222 * @returns true if a control was updated as a result of this action.
223 */
224export 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
265function setUpViewChangePipeline(control: FormControl, dir: NgControl): void {
266 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…