1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How to check if any control in a reactive form has value in Angular 2

Discussão em 'Angular' iniciado por nilanjan, Setembro 11, 2024.

  1. nilanjan

    nilanjan Guest

    I have a form in which there are 4-5 different types of control. On certain user action, I need to know if any of the controls have any value in it and it can happen on any state of the form - be it pristine or dirty. I cannot rely on the form states for this. cCan't even loop through since this.myForm.controls isn't an array type. Also this.myForm.value is always an 'object' even though no values for controls in it.

    Here is the form creation code, if that helps:

    this.searchForm = this.fb.group({
    'ids': this.fb.control([], multipleInputValidator(2)),
    'locationName': this.fb.control([], Validators.minLength(2)),
    'accountCodes': this.fb.control([], multipleInputValidator(2)),
    'regionCodes': this.fb.control([], multipleInputValidator(2)),
    'city': this.fb.control([], Validators.minLength(2)),
    'typeIds': this.fb.control([]),
    'centreIds': this.fb.control([]),
    'siteCodes': this.fb.control([]),
    'statusCode': this.fb.control([]),
    'from': this.fb.control([]),
    'to': this.fb.control([])
    });

    Continue reading...

Compartilhe esta Página