GitHub

htmx Form

Response-aware form that auto-configures the htmx response-targets extension and injects error-handling JavaScript.

<rhx-htmx-form>

Examples

Basic Form with Validation

Submits via htmx POST. On 422 validation failure, errors are swapped into the error target.

Reset on Success

The form resets automatically after a successful submission.

Server-Side Pattern

Pair with the existing HtmxValidationFailure() extension for 422 responses:

public IActionResult OnPostContact()
{
    if (!ModelState.IsValid)
    {
        return this.HtmxValidationFailure("_FormErrors", this);
    }

    return Content("<rhx-callout rhx-variant=\"success\">Saved!</rhx-callout>", "text/html");
}