Documentation menu
Getting Started
Core Concepts
Control
Interactivity
Pushing Data
HTMX Extensions
Miscellaneous
Configuration
Mutation Error
The mutation-error extension emits htmx:onMutationError for POST, PUT, PATCH, and DELETE requests with an HTTP status of 400 or higher.
Attach a handler with h.HxOnMutationError to respond to the event.
Example:
func SaveForm() *h.Element {
return h.Form(
h.PostPartial(Save),
h.NoSwap(),
h.Button(
h.Type("submit"),
h.HxOnMutationError(js.Alert("Save failed.")),
h.Text("Save"),
),
)
}
func Save(ctx *h.RequestContext) *h.Partial {
ctx.Fiber.Status(400)
return h.EmptyPartial()
}
Copy
1func SaveForm() *h.Element {
2 return h.Form(
3 h.PostPartial(Save),
4 h.NoSwap(),
5 h.Button(
6 h.Type("submit"),
7 h.HxOnMutationError(js.Alert("Save failed.")),
8 h.Text("Save"),
9 ),
10 )
11}
12
13func Save(ctx *h.RequestContext) *h.Partial {
14 ctx.Fiber.Status(400)
15 return h.EmptyPartial()
16}The extension also notifies elements with a mutation-error listener, such as a submit button inside the requesting form.