Lines
100 %
Functions
60 %
Branches
//! Data attribute definitions for autocomplete components.
//!
//! This module provides a single source of truth for HTML data attribute names
//! used by autocomplete components. Both the WASM frontend (reader) and the web
//! server templates (writer) use these definitions to ensure consistency.
/// Attribute names for autocomplete components.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AutocompleteAttr {
/// The type of autocomplete (e.g., "account", "commodity", "tag-name", "tag-value")
Type,
/// URL to fetch suggestions from
FetchUrl,
/// HTTP method for fetching (GET or POST, default: GET)
FetchMethod,
/// ID of the visible display input field
DisplayInput,
/// ID of the hidden value input field
HiddenInput,
/// ID of the currency/secondary input field (optional)
CurrencyInput,
/// ID of the dependency input (for dependent autocompletes like tag-value)
DependsOn,
/// Marker attribute indicating the component is initialized
Initialized,
/// Index for suggestion items in the dropdown
Index,
}
impl AutocompleteAttr {
/// Returns the HTML attribute name as a string slice.
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Type => "data-autocomplete",
Self::FetchUrl => "data-fetch-url",
Self::FetchMethod => "data-fetch-method",
Self::DisplayInput => "data-display-input",
Self::HiddenInput => "data-hidden-input",
Self::CurrencyInput => "data-currency-input",
Self::DependsOn => "data-depends-on",
Self::Initialized => "data-initialized",
Self::Index => "data-index",
/// CSS selectors used by autocomplete components.
pub mod selectors {
/// Selector for the autocomplete results container
pub const RESULTS_CONTAINER: &str = ".autocomplete-results";
/// Values for the autocomplete type attribute.
pub mod autocomplete_type {
/// Account autocomplete type
pub const ACCOUNT: &str = "account";
/// Commodity autocomplete type
pub const COMMODITY: &str = "commodity";
/// Tag name autocomplete type
pub const TAG_NAME: &str = "tag-name";
/// Tag value autocomplete type (depends on tag-name)
pub const TAG_VALUE: &str = "tag-value";
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_attr_names() {
assert_eq!(AutocompleteAttr::Type.as_str(), "data-autocomplete");
assert_eq!(AutocompleteAttr::FetchUrl.as_str(), "data-fetch-url");
assert_eq!(AutocompleteAttr::FetchMethod.as_str(), "data-fetch-method");
assert_eq!(
AutocompleteAttr::DisplayInput.as_str(),
"data-display-input"
);
assert_eq!(AutocompleteAttr::HiddenInput.as_str(), "data-hidden-input");
AutocompleteAttr::CurrencyInput.as_str(),
"data-currency-input"
assert_eq!(AutocompleteAttr::DependsOn.as_str(), "data-depends-on");
assert_eq!(AutocompleteAttr::Initialized.as_str(), "data-initialized");
assert_eq!(AutocompleteAttr::Index.as_str(), "data-index");
fn test_autocomplete_types() {
assert_eq!(autocomplete_type::ACCOUNT, "account");
assert_eq!(autocomplete_type::COMMODITY, "commodity");
assert_eq!(autocomplete_type::TAG_NAME, "tag-name");
assert_eq!(autocomplete_type::TAG_VALUE, "tag-value");