Merge pull request #926 from Demonthos/prevent-default-form-web

This commit is contained in:
Jonathan Kelley 2023-07-20 16:07:52 -07:00 committed by GitHub
commit af254102d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,17 +56,27 @@ impl WebsysDom {
let element = walk_event_for_id(event);
let bubbles = dioxus_html::event_bubbles(name.as_str());
if let Some((element, target)) = element {
let prevent_event;
if let Some(prevent_requests) = target
.get_attribute("dioxus-prevent-default")
.as_deref()
.map(|f| f.split_whitespace())
{
if prevent_requests
prevent_event = prevent_requests
.map(|f| f.trim_start_matches("on"))
.any(|f| f == name)
{
.any(|f| f == name);
} else {
prevent_event = false;
}
// Prevent forms from submitting and redirecting
if name == "submit" {
// On forms the default behavior is not to submit, if prevent default is set then we submit the form
if !prevent_event {
event.prevent_default();
}
} else if prevent_event {
event.prevent_default();
}
let data = virtual_event_from_websys_event(event.clone(), target);