-
-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Enter on filter field submits form #5790
Comments
Your code: <DataGrid TItem="Row" Filterable="true" Data="rows">
<DataGridColumns>
<DataGridNumericColumn Field="@nameof(Row.Id)" Displayable="false" />
<DataGridColumn Field="@nameof(Row.Name)" />
</DataGridColumns>
</DataGrid> The issue can be extracted to: <form>
<input type="text" />
</form> here when you press Enter on the input it will always submit the form. That's standart html behavior. The DataGrid is in form and with the filter input it does exactly that. It's not intended behavior here. We cannot effectively prevent that on the input itself (maybe with some weird js hack) We can solve it by:
That's my question for @stsrki - why is the DataGrid using Form? it seems it's not doing anything important. |
@David-Moreira It doesn't help unfortunatelly. The Here, the search field is used. In the simplest form of using the grid (as in my previous code block), it hits the nature of HTML, where pressing "Enter" on a single input inside a form causes a submit action. This behavior can probably be prevented with some js, but in my opinion, the easiest solution is to add a "hidden" field inside the form, which will prevent this behavior. "hidden" means btw: this bug is also "available" in blazorise docs |
This is incorrect. It should do what the name implies, not what you found it does by reading the code. By changing the button to not be of type submit, the form should not get submitted on Enter.
It should fix exactly that, because it should only trigger the submit action if a Submit button exists as far as I know. There must be something wrong or that we are missing if |
Ok, I understand the So the solution is to add this:
That should make the Because:
If just one input is present, the button type has no effect wherever it's submitted or on. So the solution makes adds the hidden text field so it will work based on the |
Does this workaround work on all browsers? I never heard that it behaves like that for a single input in a form. |
Me neither, I was under the impression that this :
Would not submit the form on enter. Maybe the spec changed? However, one of your examples, most likely reproduces the DataGrid
|
PS: I just noticed that the key thing in your examples is that a SINGLE input makes it so a form is submitted on Enter regardless. I think it's very very unlikely for the |
* Datagrid - prevents submitting form on Enter in Filter if SubmitFormOnEnter is false. closes #5790 * Creates PreventDefaultSubmitBehavior private property * Formating --------- Co-authored-by: Mladen Macanovic <[email protected]>
Blazorise Version
latest
What Blazorise provider are you running on?
None
Link to minimal reproduction or a simple code snippet
When you use the [Enter] key in a search field of a DataGrid, the whole webpage is submitted and refreshed.
This only happens hen only 1 seachfield is present in the grid. When more textual searchfield are present(even hidden) this unwanted behavior is not present.
Steps to reproduce
See example: https://github.com/tacoWanneeJama/BlazorAppGridFilter/settings
What is expected?
The webpage should off course be submitted from a Blazor page.
What is actually happening?
Page refresh
What browsers do you see the problem on?
Chrome
Any additional comments?
As workaround I now add an invisible text-field.
The text was updated successfully, but these errors were encountered: