`preventDefault()` will not prevent navigation on a form submission
Opened this issue · 0 comments
LukasBombach commented
Describe the bug
When you try to prevent a form element from element from submitting by attaching an event listener and preventing the default, it will still submit the form:
const form = document.querySelector("form");
form.addEventListener('submit', e => e.preventDefault());
/* click submit */
it should not submit the form and no navigation should happen. But it does.
To Reproduce
I did create a minimal reproducible example here:
https://github.com/LukasBombach/happy-dom-form-prevent-default-bug
- clone
- install (I used yarn
yarn install
) - run "test" npm script
yarn test
Expected behavior
Using preventDefault on a submit event of a form should stop it from navigating.
After submitting a form in happy-dom
there will be a navigation nonetheless.
Screenshots
--
Device:
- OS: macOS Sonoma 14.4.1
- Browser -
- Version -
Additional context
I can see this using vitest 1.6.0
happy-dom 14.12.0