gpt4 book ai didi

angular - 禁用表单时,响应式表单有效属性返回 false

转载 作者:行者123 更新时间:2023-12-01 09:25:29 26 4
gpt4 key购买 nike

我有这个简单的表单并用于创建和更新案例,因此对于创建案例,用户将输入数据并基于验证器我将获得 form.valid (真假)。
在更新的情况下,我只是从 api 获取数据并将此值设置为表单并使表单禁用;

this.form = fb.group({
name: ['', Validators.required],
lastName: ['', Validators.required],
address: [''],
});

所以当我禁用表单时,有效值总是 false ;
 ngOnInit() {
this.form.patchValue({
name: 'name',
lastName: 'Last Name'
});

this.form.disable();
}

stackblitz example

最佳答案

这是对的。文档说:

A control is valid when its status is VALID.


状态文档说:

The validation status of the control. There are four possible validation status values:

  • VALID: This control has passed all validation checks.
  • INVALID: This control has failed at least one validation check.
  • PENDING: This control is in the midst of conducting a validation check.
  • DISABLED: This control is exempt from validation checks.

您的表单已禁用,因此无效。

关于angular - 禁用表单时,响应式表单有效属性返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51466641/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com