fix(typeahead): fix the handler name generation

This commit is contained in:
ryan 2025-04-18 14:53:55 +03:00
parent fd0d4a5f38
commit 7d36bac77f

View file

@ -1,3 +1,4 @@
use leptos::*;
use wasm_bindgen::prelude::*;
use crate::models::item::WikidataSuggestion;
@ -296,11 +297,14 @@ fn initialize_typeahead(
}) as Box<dyn FnMut(web_sys::Event, JsValue)>);
// Register global handler
let handler_name = format!("handler_{}", input_id);
let handler_name = format!("handler_{}", input_id.replace("-", "_"));
log!("[TYPEAHEAD] Registering handler with name: {}", handler_name);
js_sys::Reflect::set(
&js_sys::global(),
&handler_name.clone().into(),
closure.as_ref(),
closure.as_ref().unchecked_ref(),
).unwrap();
closure.forget();
@ -360,7 +364,7 @@ fn initialize_typeahead(
}}
"#,
id = input_id,
handler = handler_name.replace('-', "_")
handler = handler_name
);
log!("[RUST] Initialization script: {}", init_script);