Class: H_ui_autocomplete

H_ui_autocomplete

UI class for autocomplete input fields, the rows being searched in the database at each keystroke.
Handles search, selection, and keyboard navigation.
Possible settings for H_ui_autocomplete:
- name: string (name of the field)
- table_name: string (table to search in)
- field_name: string (field to search in)
- submit: boolean (submit the form on selection)
- new_value: boolean (allow entering a new value)
- toreturn: string ('id' or 'text', value to return on selection)
- confirm: string|boolean (confirmation message on selection)
- callback: string|function (function name or function to call on selection)
Used as h.libs.ui_autocomplete.

new H_ui_autocomplete(dom_id)

ui.js, line 2607
Name Type Description
dom_id string dom_id for the created autocomplete

Members

instances

All autocomplete instances by dom_id (own registry, see H_ui_completer).

Methods

can_open(){boolean}

ui.js, line 2678
The list is only opened when it has a row to show: an autocomplete without result stays closed.
Returns:
Type Description
boolean

display_search_result(result, open)

ui.js, line 2737
Displays the search results in the dropdown.
Adds event listeners to each result item for selection.
Name Type Description
result string HTML string of results.
open boolean Whether to open the dropdown.

get_active_element(){HTMLElement|false}

ui.js, line 2670
The active row is held by position in the list, not by reference.
Returns:
Type Description
HTMLElement | false

on_click_search_result(evt)

ui.js, line 2753
Handles click event on a search result item.
Sets the value, closes the dropdown, and triggers callback or confirmation if needed.
Name Type Description
evt Event The click event.

on_focus(evt)

ui.js, line 2687
Handles focus event on the input field.
Opens the autocomplete dropdown with show()
Name Type Description
evt Event The focus event.

on_hover_search_result(evt)

ui.js, line 2779
Handles mouse hover on a search result item.
Updates the active (highlighted) result.
Name Type Description
evt Event The mousemove event.

on_input(open)

ui.js, line 2695
Handles input event on the search field.
Sends AJAX request if input length > 1 and displays results.
Name Type Default Description
open boolean true optional Whether to open the dropdown after input.

on_key_down(evt)

ui.js, line 2795
Handles keydown events for navigation and selection.
Supports ArrowUp, ArrowDown, Enter, and new value logic.
Name Type Description
evt KeyboardEvent The keyboard event.