我想通过按 Enter 键来提交表单,而不是在编辑任何字段并启用更新按钮后单击更新按钮,如下截图所示。
此更新表单是一个对话框,单击表行上的编辑功能即可打开该对话框。

案例:现在表单已在Emp Code字段中编辑并突出显示,因此单击 Enter 键后应提交此表单。
下面是 HTML 中更新表单的代码示例。
<mat-card-content>
<form class="example-form" [formGroup]="docForm">
<table>
<tr>
.
.
<td>
<mat-form-field appearance="outline">
<mat-label>Emp Code</mat-label>
<input matInput name="empCode" formControlName="empCd" maxLength = "4" >
</mat-form-field>
</td>
.
.
</tr>
</table>
</form>
</mat-card-content>
<button mat-raised-button style="width: 95px;" color="primary" [disabled]='docForm.invalid || !docForm.dirty (click)="update()"> Update </button>
Run Code Online (Sandbox Code Playgroud)
我尝试了一些方法,但没有按预期工作。
<button mat-raised-button (keyup.enter)="!($event.target.tagName == 'TEXTAREA' || $event.target.tagName == 'BUTTON')"
style="width: 95px;" color="primary" [disabled]='docForm.invalid || !docForm.dirty' (click)="update()"> Update </button>
Run Code Online (Sandbox Code Playgroud)
预先感谢您对此的任何帮助。