htmgo/htmgo-site/pages/docs/htmx-extensions/mutation-error.go
maddalax 35877a1b2e
New Docs (#63)
* scripting enhancements

* tests

* cleanup / tests

* new docs wip

* add more docs

* more updates

* add caching docs

* add sse docs

* more docs

* sidebar, and fix navigation blocks

* remove old docs

* set proper meta

* fixes
2024-10-30 13:27:42 -05:00

42 lines
1.1 KiB
Go

package htmx_extensions
import (
"github.com/maddalax/htmgo/framework/h"
. "htmgo-site/pages/docs"
"htmgo-site/ui"
)
func MutationError(ctx *h.RequestContext) *h.Page {
return DocPage(
ctx,
h.Div(
h.Class("flex flex-col gap-3"),
Title("Mutation Error"),
Text(`
The 'mutation-error' extension allows you to trigger an event when a request returns a >= 400 status code.
This is useful for things such as letting a child element (such as a button) inside a form know there was an error.
`),
Text(`<b>Example:</b>`),
ui.GoCodeSnippet(MutationErrorExample),
Text(`It can also be used on children elements that do not make an xhr request, if you combine it with the TriggerChildren extension.`),
NextStep(
"mt-4",
PrevBlock("Trigger Children", DocPath("/htmx-extensions/trigger-children")),
NextBlock("Tailwind Intellisense", DocPath("/misc/tailwind-intellisense")),
),
),
)
}
const MutationErrorExample = `
h.Form(
h.HxTriggerChildren(),
h.HxMutationError(
js.Alert("An error occurred"),
),
h.Button(
h.Type("submit"),
h.Text("Submit"),
),
)
`