Lines
0 %
Functions
Branches
100 %
use web_sys::Element;
use super::account::AccountAutocomplete;
use super::commodity::CommodityAutocomplete;
use super::tag::{TagNameAutocomplete, TagValueAutocomplete};
use crate::data_attrs::{AutocompleteAttr, autocomplete_type};
/// Creates and attaches an autocomplete component based on the type attribute.
///
/// Reads `data-autocomplete` from the wrapper element and dispatches to the
/// appropriate type-specific handler.
#[must_use]
pub fn create_autocomplete(wrapper: &Element) -> Option<()> {
let ac_type = wrapper.get_attribute(AutocompleteAttr::Type.as_str())?;
match ac_type.as_str() {
autocomplete_type::ACCOUNT => AccountAutocomplete::attach(wrapper.clone()),
autocomplete_type::COMMODITY => CommodityAutocomplete::attach(wrapper.clone()),
autocomplete_type::TAG_NAME => TagNameAutocomplete::attach(wrapper.clone()),
autocomplete_type::TAG_VALUE => TagValueAutocomplete::attach(wrapper.clone()),
_ => {
web_sys::console::warn_1(&format!("Unknown autocomplete type: {ac_type}").into());
None
}