Angular7+ng-zorro form validation is invalid

problem description

the form is nested in model. When you open a new form, click OK directly and no error message is displayed. The dirty attribute starts with false

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)
/ / submit new modifications
submitForm (): void {

for (let key in this.validateForm.controls) {
  this.validateForm.controls[ key ].markAsPristine();
  this.validateForm.controls[ key ].updateValueAndValidity();
}
console.log(this.validateForm.get("name").dirty);

}
ngOnInit () {

this.validateForm = this.fb.group({
  name : [null, [ Validators.required ]],
  price : [null, [ Validators.required ]],
  arr: [null,[ Validators.required ]],
  time: [null,[ Validators.required ]],
  remark: [null]
});

}

what result do you expect? What is the error message actually seen?

clipboard.png

May.13,2022

Today, I suddenly found that I had written a wrong place when I looped formControl when submitting. The correct code is

.
for (let key in this.validateForm.controls) {
   this.validateForm.controls[ key ].markAsDirty();  //formControl
   this.validateForm.controls[ key ].updateValueAndValidity();
}

but the problem that beginners need to pay attention to is that the judgment of validateForm.valid should also be added. Even if the form validation indicates an error, the subsequent submission code will still execute

.

I have the same problem, but the code is the same as the blogger's, but the form form is still invalid. Would like to ask what went wrong with this question? Thank you

Menu