Hello ,
I woould like to implement a Drop File like this example (JS):
https://www.html5rocks.com/en/tutorials/file/dndfiles/
So I did that :
raw_ev(Ev::DragOver, |event| {
event.stop_propagation();
event.prevent_default();
//event.data_transfer().dropEffect = 'copy';
Msg::DropFile
}),
raw_ev(Ev::Drop, |event| {
//let files = event.data_transfer().files();
Msg::DropFile
}),
But I'm stuck with
parsing web_sys::Event to web_sys::DragEvent
beceause I need the method data_transfer which is only in DragEvent
Thanks for your help
Hi. See https://github.com/David-OConnor/seed/pull/230/files (related PR)
A quote from Martin's PR that goes directly to getting:data_transfer:
self.dyn_into::<web_sys::DragEvent>()
.expect("cannot cast given event into DragEvent")
This is due to websys::Event itself not having that property, but it can be cast as a DragEvent using dyn_into or dyn_ref. This is a quirk of the DOM spec, in combination with Rust's type system. It's one of the reasons we have different types of event functions: They cast Event as KeyboardEvent, MouseEvent etc.
So the commented code in your example might look like:
event.dyn_into::<web_sys::DragEvent>()
.expect("cannot cast given event into DragEvent")
.data_transfer()
.dropEffect = 'copy';
Thanks a lot
Most helpful comment
A quote from Martin's PR that goes directly to getting:
data_transfer:This is due to
websys::Eventitself not having that property, but it can be cast as aDragEventusingdyn_intoordyn_ref. This is a quirk of the DOM spec, in combination with Rust's type system. It's one of the reasons we have different types of event functions: They castEventasKeyboardEvent,MouseEventetc.So the commented code in your example might look like: