Tuesday 22 September 2020

How to add error to child form controls in angular without silencing child's own validators

this.form = this.fb.array([
  this.fb.group({ 
    username: [null, Validators.required]
  }),
  this.fb.group({ 
    username: [null, Validators.required]
  }),
  ...
], uniqueUsernameValidator)

const uniqueUsernameValidator = control => {
  // find duplicate
  
  // when flagging the error
  control.get('0.username').setErrors(ifThereIsAnError) // where `ifThereIsAnError` could be null
}

Somehow uniqueUsernameValidator is silencing the required validation specified by child form fields. How to solve this problem?



from How to add error to child form controls in angular without silencing child's own validators

No comments:

Post a Comment