DioxusLabs / DioxusLabs/dioxus
Form reloads with prevent_default() in EventHandler from struct
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
Calling `prevent_default()` inside an `EventHandler` returned by a struct method does not prevent the default form submission (page reload), whereas an inline closure works as expected.
**Steps To Reproduce**
Steps to reproduce the behavior:
- Clone the repository here https://github.com/T00fy/dioxus_form_test and run the app with `dx serve`
---
- In **Scenario A (Problematic Form)**, type a value and click **Submit**.
- Observe console logs show `prevent_default()` called, and the page reloads (`/?data_a=…`).
- Async task never finishes due to the page reloading.
---
- In **Scenario B (Working Form)**, type a value and click **Submit**.
- Observe no reload and the form’s status updates in-place.
- Async task completes properly.
---
- In **Scenario C (Debug Form)**, repeat and note that despite an immediate `prevent_default()`, the page still reloads.
- Async task never finishes due to the page reloading.
**Expected behavior**
Including `prevent_default()` should not cause a page to reload. I'm also not sure why the async task never executes when the page reloads.
**Minimum reproducible example**
See here: https://github.com/T00fy/dioxus_form_test
**Environment:**
- Dioxus version: v0.6.3
- Rust version: rustc 1.87.0 (17067e9ac 2025-05-09)
- OS info: Fedora
- App platform: web
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.