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

Prevent Blazor WebAssembly submiting form on pressing enter

$
0
0

I just spent ages trying to get Blazor not to submit and reload the page but fire off my methods instead on enter key. With

<form><input type="text" class="form-text" @bind-value:event="oninput" @onkeydown="Enter" @bind-value="@searchString" /><button type="button" class="btn btn-primary" @onclick="Search">Search</button></form>

Whenever I hit enter the page would get reloaded if I used the enter key instead of click, preventing the results from showing. So I added

<button type="submit" disabled hidden></button>

Which fixed it.

Now this to me looks like a workaround. Is there a more elegant way to do this? If I had the original button as submit it wouldnt work either. I think this works because there is a submit button for the enter key to hit, but being disabled it cant do anything.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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