Skip to content

Allow callable functions to be passed directly into hx_* attributes#884

Open
AaineeSinha wants to merge 1 commit into
AnswerDotAI:mainfrom
AaineeSinha:main
Open

Allow callable functions to be passed directly into hx_* attributes#884
AaineeSinha wants to merge 1 commit into
AnswerDotAI:mainfrom
AaineeSinha:main

Conversation

@AaineeSinha

Copy link
Copy Markdown

Solves #864

Summary of the Issue & Changes

1. What the Problem Was

When passing router-decorated callable functions directly into hx_* attributes (like hx_post, hx_get, etc.), FastHTML did not automatically resolve them to their string URL paths. Developers were forced to explicitly wrap every function in str(), creating unnecessary friction, type-annotation mismatches, and messy code when attempting to use reverse routing.

2. What I Changed (The Solution)

I implemented automatic string resolution for callables passed into HTMX attributes to enable clean, native reverse routing.

  • Core Attribute Logic (fasthtml/components.py): Modified the component rendering logic to intercept callables in hx_* proxy attributes and automatically convert them to their corresponding string paths internally.
  • Documentation & Notebooks (nbs/api/01_components.ipynb): Updated the source notebook to formally support this behavior, adjusted the component documentation examples, and added structural verification tests to ensure decorated functions resolve perfectly without manual casting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant