3 ms·
> a complex multi-step form with a bunch of frontend state and validations? HTMX can handle this perfectly. "Frontend state" in the context of a form is...the
by smallerfish 3y ago
> a complex multi-step form with a bunch of frontend state and validations?
HTMX can handle this perfectly.
"Frontend state" in the context of a form is...the form. Add as many hidden fields as you need, and you've captured the state.
Validation - no problem. The "backend" can choose what response it sends, and to where in the page. Your form fails to validate? Annotate the failures in the markup, send back a fragment that replaces the fields that fail, all good.
It's also not an all-or-nothing proposition; you can have Javascript alongside HTMX. Add "hooks" into htmx.load(), and they'll be fired every time a new fragment comes back; I like to use querySelectorAll to look for elements marked up with whatever attributes are applicable, and then manipulate them in whatever way I need (e.g. to turn markup into pretty/interactive charts).