[英]Disable a button after submitting form when form already has form.valid field set for [disabled] field
I have a reactive form, which consists of a button and two other fields.我有一个反应式表单,它由一个按钮和其他两个字段组成。
I have set a validator.我已经设置了一个验证器。 If validator is true, I am enabling the button via 'FormName.valid' and similarly if it's false, the button is disabled
如果验证器为真,我将通过“FormName.valid”启用按钮,同样如果为假,则按钮被禁用
What I want?我想要的是?
I want to disable button, after clicking on Submit button as well我想禁用按钮,也点击提交按钮后
What I tried?我尝试了什么?
I tried FormName.reset()
, which does disable the button, but then it shows errors in the background for empty two fields, while my spinner is running.我尝试了
FormName.reset()
,它确实禁用了按钮,但是当我的微调器正在运行时,它会在后台为空的两个字段显示错误。 (So, I don't want to do like this) (所以,我不想这样做)
HTML: HTML:
<form [formGroup]="FormName" (ngSubmit)=sendData()>
// Two other fields here
<div id="frame-send-button" text-center>
<button [disabled]="!FormName.valid" type="submit">
Submit
</button>
</form>
Typescript打字稿
Form Initialization表单初始化
this.FormName= new FormGroup({
field1: new FormControl(this.field1value, Validators.required),
field2: new FormControl(this.field2value)
}, IsFutureValidator('somevalidator'));
Any suggestions?有什么建议?
document.yourQuerySelector('submitForm').setAttribute('disabled');
This will add an attribute of your choice to any element.这会将您选择的属性添加到任何元素。 "Disabled" will work in this case.
在这种情况下,“禁用”将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.