I have some Angular 6 forms and I focus on the first available field. They contain a submit button and when I press enter, the form is submitted automatically and the ngSubmit event is triggered.
There is one particular form which only contains a radio group, and I am not focusing on any field. In this case, ngSubmit is not triggered.
If I click on a radio button and then press enter, the form submits correctly.
Is there any way of making the form submit on enter even if none of the fields within the form are focused? Should I focus on the form itself somehow?
Form:
<form (ngSubmit)="onSubmit()" [formGroup]="form">
<mat-radio-group [formControl]="control" name="test">
<mat-radio-button *ngFor="let option of options" [value]="option.key">
{{option.value}}
</mat-radio-button>
</mat-radio-group>
<button>Submit</button>
</form>
Stackblitz: https://stackblitz.com/edit/angular-arcwjv?file=src/app/app.component.html
type=submit
to the button. – RoadEx[navigable]=true
flag, which prevented the enter key from being used for form submit. Hope this helps someone else. – RMorrisey