yewstack / yew

Rust / Wasm framework for creating reliable and efficient web applications
https://yew.rs
Apache License 2.0
30.79k stars 1.43k forks source link

'no SubmitEvent in `events' -- I can't seem to find the SubmitEvent. #1455

Closed PatrickMcLennan closed 4 years ago

PatrickMcLennan commented 4 years ago

Question

I need to get the SubmitEvent in order to perform a preventDefault Following the docs here, I would assume that...

use yew::events::SubmitEvent

would work, and it does not. Where can I find this struct in order to define it properly?

What I've tried (optional)

use yew::events::SubmitEvent use yew::events::{SubmitEvent} use yew::SubmitEvent and a million other goofy things out of desperation.

Each time, I get hit with some variant of "no SubmitEvent in ____".

Screen Shot 2020-07-26 at 2 18 47 PM

Am I doing something wrong? I can't find this struct anywhere, and Rust won't compile without me defining, pictured below.

Screen Shot 2020-07-26 at 2 14 20 PM Screen Shot 2020-07-26 at 2 14 28 PM
siku2 commented 4 years ago

SubmitEvent only exists in stdweb. If you're using web-sys the appropriate type is FocusEvent. See GlobalEventHandlers.onsubmit. The event type is the same as the Javascript type in most cases when using web-sys.

We'll hopefully have better documentation for the event types soon (#1450)

siku2 commented 4 years ago

1450 has been resolved (but the new documentation isn't deployed to yew.rs yet). Closing this.

PatrickMcLennan commented 4 years ago

Thanks for the answer / clarification @siku2 .

rhymu8354 commented 3 years ago

I ran into this same "misunderstanding" today. I'm confused because it seems to me that the event generated by submitting a form has little if anything to do with focus. The GlobalEventHandlers.onsubmit MDN documentation doesn't mention "focus", however it might just be something a more experienced web developer would associate intuitively. I'd really appreciate a bit more info on the subject. Thanks!

PatrickMcLennan commented 3 years ago

@rhymu8354 even as a FE web developer by trade it didn't dawn on me to associate the 2 events either. Submit and focus events are separate and do separate things. In any FE library or framework I've used, in this scenario you'd be dealing solely with the submit event. Speaking candidly I'm not so sure this would be intuitive to most but I'll also admit to being far more junior with rust and the wasm ecosystem than I am with more "standard" html form handlers, so, this could be more intuitive to a rust/yew developer than I give it credit for.

Regardless this seems to be more of an issue with web-sys than yew, but I agree that if their docs still don't cover this it would be helpful.