diff --git a/src/components/items_list.rs b/src/components/items_list.rs index b2ecf98..2568598 100644 --- a/src/components/items_list.rs +++ b/src/components/items_list.rs @@ -1035,10 +1035,67 @@ pub fn ItemsList( // Update the focused item ID when input receives focus let item_id = item.id.clone(); let set_focused_item_id = set_focused_item_id.clone(); - + let input_id = format!("name-input-{}-{}", index, item.id); + move |_| { log!("Name input focused: item_id={}", item_id); set_focused_item_id.set(Some(item_id.clone())); + + // Force Bloodhound to initialize/reinitialize + let js_code = format!( + r#" + try {{ + console.log("[DEBUG] Input focused:", "{}"); + + // Get the input element + const inputElement = document.getElementById("{}"); + if (!inputElement) {{ + console.error("[DEBUG] Input element not found:", "{}"); + return; + }} + + // Check if Bloodhound is initialized + if (!window.bloodhoundInstances || !window.bloodhoundInstances["{}"]) {{ + console.warn("[DEBUG] Bloodhound not initialized for {}, attempting to reinitialize", "{}"); + + // Try to reinitialize Bloodhound + if (typeof window.initTypeahead === "function") {{ + window.initTypeahead("{}", "{}"); + console.log("[DEBUG] Reinitialized Bloodhound for {}", "{}"); + }} else {{ + console.error("[DEBUG] initTypeahead function not available "); + }} + }} else {{ + console.log("[DEBUG] Bloodhound already initialized for {}", "{}"); + + // Force a query if there's a value + if (inputElement.value) {{ + // Directly manipulate the DOM to trigger Bloodhound + const currentValue = inputElement.value; + + // Clear and reset the value to force Bloodhound to update + inputElement.value = ""; + setTimeout(function() {{ + inputElement.value = currentValue; + inputElement.dispatchEvent(new Event("input", {{ bubbles: true }})); + console.log("[DEBUG] Forced input event for {} with value: {}", "{}", currentValue); + }}, 10); + }} + }} + }} catch (e) {{ + console.error("[DEBUG] Error in focus handler:", e); + }} + "#, + input_id, + input_id, input_id, + input_id, input_id, input_id, + input_id, input_id, input_id, input_id, + input_id, input_id, + input_id, input_id, input_id + ); + + // Execute the JavaScript + let _ = js_sys::eval(&js_code); } }) node_ref=node_ref.clone()