Inputs

Hidden input rendering for HTMX state sync.

render_hidden_inputs


def render_hidden_inputs(
    ids:TokenSelectorHtmlIds, # HTML IDs for this instance
    state:Optional=None, # current state
    oob:bool=False, # render with hx-swap-oob
)->Any: # tuple of anchor and focus hidden inputs

Render hidden inputs for HTMX form submission.


build_include_selector


def build_include_selector(
    ids:TokenSelectorHtmlIds, # HTML IDs for this instance
)->str: # CSS selector string for hx_include

Build a CSS selector for including anchor and focus inputs in HTMX requests.

from cjm_fasthtml_token_selector.core.models import TokenSelectorState
from cjm_fasthtml_token_selector.core.html_ids import TokenSelectorHtmlIds

ids = TokenSelectorHtmlIds(prefix="ts0")
state = TokenSelectorState(anchor=3, focus=7)

inputs = render_hidden_inputs(ids, state)
assert len(inputs) == 2
print("render_hidden_inputs test passed!")

selector = build_include_selector(ids)
assert "#ts0-anchor" in selector
assert "#ts0-focus" in selector
print(f"Include selector: {selector}")
print("build_include_selector test passed!")
render_hidden_inputs test passed!
Include selector: #ts0-anchor, #ts0-focus
build_include_selector test passed!