[英]Angular Reactive form custom validators doesn't work after form reset
I have been using reactive forms since a while but, right now i am facing a issue while resetting it. 一段时间以来,我一直在使用反应形式,但是现在我在重置它时遇到了问题。 My aim is inline CRUD operations to a table of records.
我的目标是对记录表进行内联CRUD操作。
Create Form: 创建表格:
formGroupName.formBuilder.group({
fieldName: '',
fieldName1: ''
}, { validator: CustomValidator });
Form Reset: 表格重置:
formGroupName.reset({
fieldName: ['', Validators.required],
fieldName1: ['', Validators.required]
});
While adding a record, i display a form to the top of the table and i also perform a this.formGroupName.reset() function. 添加记录时,我在表格顶部显示一个表单,并且还执行this.formGroupName.reset()函数。 And afterwards i reset it and i click the add button form gets reset and CustomValidator doesn't work at all whereas the other validators(required) do work fine.
然后我重置它,然后单击“添加”按钮,表格被重置, CustomValidator根本不起作用,而其他验证器(必需)也能正常工作。 I have tried the same thing by replacing reset with patch value.
我已经尝试过通过将重置替换为补丁值来尝试同样的事情。
Custom validators do work when i write the code for creating the form again after the reset function which i feel is not the right solution as it makes me to write the same code again before and after calling the reset function. 当我在reset函数之后再次编写用于创建表单的代码时,自定义验证程序会起作用,我认为这不是正确的解决方案,因为它使我在调用reset函数之前和之后再次编写相同的代码。
Please advise. 请指教。
on FormReset try this. 在FormReset上尝试此。 worked for me
为我工作
formGroupName.reset({
fieldName: ('',[ Validators.required, CustomerVaidator]),
fieldName1: ('',[ Validators.required, CustomerVaidator])
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.