How do I add an input
event listener to an HtmlInputElement
/HtmlTextAreaElement
. I'm using web-sys
and read this, but following that, all the elements I use inside the closure (in this case especially the input
element) get moved into the closure and I can't attach the listener afterwards.
let closure = Closure::wrap(Box::new(|_: web_sys::InputEvent| {
console_log!("{}", input.value());
}) as Box<dyn FnMut(_)>);
input.add_event_listener_with_callback("input", closure.as_ref().unchecked_ref())?;
// ^
// Doesn't work because the `input` variable was moved into the closure.
Concretely speaking I get:
borrow of moved value: `input`