fix(items_list): enhance input focus handling and reinitialize Bloodhound on focus
This commit is contained in:
parent
cd47be500f
commit
8799d5c144
1 changed files with 58 additions and 1 deletions
|
@ -1035,10 +1035,67 @@ pub fn ItemsList(
|
||||||
// Update the focused item ID when input receives focus
|
// Update the focused item ID when input receives focus
|
||||||
let item_id = item.id.clone();
|
let item_id = item.id.clone();
|
||||||
let set_focused_item_id = set_focused_item_id.clone();
|
let set_focused_item_id = set_focused_item_id.clone();
|
||||||
|
let input_id = format!("name-input-{}-{}", index, item.id);
|
||||||
|
|
||||||
move |_| {
|
move |_| {
|
||||||
log!("Name input focused: item_id={}", item_id);
|
log!("Name input focused: item_id={}", item_id);
|
||||||
set_focused_item_id.set(Some(item_id.clone()));
|
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()
|
node_ref=node_ref.clone()
|
||||||
|
|
Loading…
Add table
Reference in a new issue