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 leptos::*;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use crate::models::item::WikidataSuggestion; use crate::models::item::WikidataSuggestion;
@ -295,12 +296,15 @@ fn initialize_typeahead(
} }
}) as Box<dyn FnMut(web_sys::Event, JsValue)>); }) as Box<dyn FnMut(web_sys::Event, JsValue)>);
// Register global handler // 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::Reflect::set(
&js_sys::global(), &js_sys::global(),
&handler_name.clone().into(), &handler_name.clone().into(),
closure.as_ref(), closure.as_ref().unchecked_ref(),
).unwrap(); ).unwrap();
closure.forget(); closure.forget();
@ -360,7 +364,7 @@ fn initialize_typeahead(
}} }}
"#, "#,
id = input_id, id = input_id,
handler = handler_name.replace('-', "_") handler = handler_name
); );
log!("[RUST] Initialization script: {}", init_script); log!("[RUST] Initialization script: {}", init_script);