Documentation
¶
Overview ¶
package responsetargets allows you to specify different target elements to be swapped when different HTTP response codes are received.
Index ¶
Examples ¶
Constants ¶
View Source
const Error errorCode = "error"
Error is a status code that covers all 4xx and 5xx HTTP response codes.
View Source
const Extension htmx.Extension = "response-targets"
Extension allows you to specify different target elements to be swapped when different HTTP response codes are received.
Install ¶
<script src="https://unpkg.com/htmx.org@1.9.12/dist/ext/response-targets.js"></script>
Extension: response-targets
Variables ¶
This section is empty.
Functions ¶
func Target ¶
Target specifies a target element to be swapped when specific HTTP response codes are received.
Extension: response-targets
Example (Code) ¶
package main import ( "fmt" "net/http" "github.com/will-wow/typed-htmx-go/htmx" "github.com/will-wow/typed-htmx-go/htmx/ext/responsetargets" ) var hx = htmx.NewStringAttrs() func main() { attr := responsetargets.Target(hx, responsetargets.Status(http.StatusNotFound), htmx.TargetRelative(htmx.Next, "div")) fmt.Println(attr) }
Output: hx-target-404='next div'
Example (Error) ¶
package main import ( "fmt" "github.com/will-wow/typed-htmx-go/htmx" "github.com/will-wow/typed-htmx-go/htmx/ext/responsetargets" ) var hx = htmx.NewStringAttrs() func main() { attr := responsetargets.Target(hx, responsetargets.Error, htmx.TargetThis) fmt.Println(attr) }
Output: hx-target-error='this'
Example (Wildcard) ¶
package main import ( "fmt" "github.com/will-wow/typed-htmx-go/htmx" "github.com/will-wow/typed-htmx-go/htmx/ext/responsetargets" ) var hx = htmx.NewStringAttrs() func main() { attr := responsetargets.Target(hx, responsetargets.Wildcard(4, 0), htmx.TargetRelative(htmx.Next, "div")) fmt.Println(attr) }
Output: hx-target-40*='next div'
Example (WildcardX) ¶
package main import ( "fmt" "github.com/will-wow/typed-htmx-go/htmx" "github.com/will-wow/typed-htmx-go/htmx/ext/responsetargets" ) var hx = htmx.NewStringAttrs() func main() { attr := responsetargets.Target(hx, responsetargets.WildcardX(4, 0), htmx.TargetRelative(htmx.Next, "div")) fmt.Println(attr) }
Output: hx-target-40x='next div'
Types ¶
Click to show internal directories.
Click to hide internal directories.