Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4213

EditForm - How can I prevent submit on pressing enter key

$
0
0

I've found this article but I'm having a hard time to understand how can I prevent submit on "enter" key independently by any <input>

<EditForm Model="exampleModel" OnValidSubmit="HandleValidSubmit"><DataAnnotationsValidator /><ValidationSummary /><InputText id="name" @bind-Value="exampleModel.Name" /><InputText id="name2" @bind-Value="exampleModel.Name2" /><button type="submit">Submit</button></EditForm>
@code {    private ExampleModel exampleModel = new ExampleModel();    private void HandleValidSubmit()    {        Console.WriteLine("OnValidSubmit");    }    public class ExampleModel    {         [Required]         [StringLength(10, ErrorMessage = "Name is too long.")]         public string Name { get; set; }         public string Name2 {get; set;}    }}

Use Case

Enter key On HTML forms if you are filling out a text box and press the enter key it will submit the form, even if you haven't finished filling in the rest of the information. There are many websites which use this feature such as Google search box will submit when you press the enter key. This works because you only have one text box to fill out, but if there are more than one field to fill in you don't want the form to submit on the enter key.


Viewing all articles
Browse latest Browse all 4213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>