Search code examples
angularangular6angular-reactive-formsangular-formsangular4-forms

Patching Items Doesn't Update Validity in Angular


I've a problem because after i submit the form, even though there's a value, the "field is required" doesn't disappear. It supposed to disappear. Is there something wrong with my validity? Please see this link See this link

TS

patchValues(id, i) {
let x = (<FormArray>this.addForm.controls['rows']).at(i);

const selectedIngredient = this.ingredients.find(y => y.id == id);

x.patchValue({
  unit_price: selectedIngredient.price
});

}


Solution

  • In these cases, you have to trigger a validity check with (for example) :

    x.patchValue({
      unit_price: selectedIngredient.price
    });
    x.get('unit_price').markAsTouched();
    

    When patching a value, validators aren't executed.

    Working fiddle