From 8946944d68f592d5c1f089dd6cc6ed15c012945e Mon Sep 17 00:00:00 2001 From: Vinicius Gobbo Antunes de Oliveira Date: Thu, 17 Aug 2023 14:57:09 +0200 Subject: [PATCH] DOC: Add note about form prevent_default behavior. (#1343) * Add note about form prevent_default behavior. * Make the default behavior clear on forms with attached event handlers. --- docs/guide/src/en/interactivity/event_handlers.md | 2 ++ docs/guide/src/pt-br/interactivity/event_handlers.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/guide/src/en/interactivity/event_handlers.md b/docs/guide/src/en/interactivity/event_handlers.md index 4c77cef1ec..4e332adf94 100644 --- a/docs/guide/src/en/interactivity/event_handlers.md +++ b/docs/guide/src/en/interactivity/event_handlers.md @@ -51,6 +51,8 @@ Any event handlers will still be called. > Normally, in React or JavaScript, you'd call "preventDefault" on the event in the callback. Dioxus does _not_ currently support this behavior. Note: this means you cannot conditionally prevent default behavior based on the data in the event. +> Note about forms: if an event handler is attached to the `onsubmit` event of a form, default behavior is to **not submit it**, meaning having `prevent_default: "onsubmit"` will submit it in this case. + ## Handler Props Sometimes, you might want to make a component that accepts an event handler. A simple example would be a `FancyButton` component, which accepts an `on_click` handler: diff --git a/docs/guide/src/pt-br/interactivity/event_handlers.md b/docs/guide/src/pt-br/interactivity/event_handlers.md index 12aad321ed..8b3d757efb 100644 --- a/docs/guide/src/pt-br/interactivity/event_handlers.md +++ b/docs/guide/src/pt-br/interactivity/event_handlers.md @@ -64,3 +64,5 @@ Então, você pode usá-lo como qualquer outro manipulador: > Nota: assim como qualquer outro atributo, você pode nomear os manipuladores como quiser! Embora eles devam começar com `on`, para que o prop seja automaticamente transformado em um `EventHandler` no local da chamada. > > Você também pode colocar dados personalizados no evento, em vez de, por exemplo, `MouseData` + +> Nota sobre formulários: se um manipulador de evento está anexado ao evento `onsubmit` em um formulário, o comportamento padrão é de **não submetê-lo**. Portanto, especificar `prevent_default: "onsubmit"` irá submetê-lo. \ No newline at end of file