hx

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Get issues a GET request to the specified URL
	AttrGet = "hx-get"
	// Post issues a POST request to the specified URL
	AttrPost = "hx-post"
	// Put issues a PUT request to the specified URL
	AttrPut = "hx-put"
	// Patch issues a PATCH request to the specified URL
	AttrPatch = "hx-patch"
	// Delete issues a DELETE request to the specified URL
	AttrDelete = "hx-delete"
	// Trigger specifies the event that triggers the request
	AttrTrigger = "hx-trigger"
	// Target specifies the target element to swap the response into
	AttrTarget = "hx-target"
	// Swap specifies how the response will be swapped in
	AttrSwap = "hx-swap"
	// SwapOob allows you to specify that some content in a response should be swapped into the DOM somewhere other than the target
	AttrSwapOob = "hx-swap-oob"
	// Include includes additional element values in the request
	AttrInclude = "hx-include"
	// Params configures the parameters submitted with the request
	AttrParams = "hx-params"
	// Encoding changes the request encoding type
	AttrEncoding = "hx-encoding"
	// Vals adds values to the request parameters
	AttrVals = "hx-vals"
	// Vars adds variables to the htmx request context
	AttrVars = "hx-vars"
	// Confirm shows a confirm dialog before issuing the request
	AttrConfirm = "hx-confirm"
	// Disable disables htmx processing for the element and its children
	AttrDisable = "hx-disable"
	// Disinherit controls attribute inheritance
	AttrDisinherit = "hx-disinherit"
	// Boost progressively enhances links and forms to use AJAX
	AttrBoost = "hx-boost"
	// PushURL pushes the URL into the browser history
	AttrPushURL = "hx-push-url"
	// ReplaceURL replaces the URL in the browser location bar
	AttrReplaceURL = "hx-replace-url"
	// Select selects a subset of the response to swap
	AttrSelect = "hx-select"
	// SelectOob selects content from a response to be swapped in via swap-oob
	AttrSelectOob = "hx-select-oob"
	// Indicator specifies the element to use as a loading indicator
	AttrIndicator = "hx-indicator"
	// Headers specifies headers to be submitted with the request
	AttrHeaders = "hx-headers"
	// Ext specifies extensions to use
	AttrExt = "hx-ext"
	// Inherit controls attribute inheritance
	AttrInherit = "hx-inherit"
	// Sync controls synchronization of requests
	AttrSync = "hx-sync"
	// Request controls various aspects of the request
	AttrRequest = "hx-request"
	// History controls history cache behavior
	AttrHistory = "hx-history"
	// HistoryElt specifies the element to snapshot for history
	AttrHistoryElt = "hx-history-elt"
	// Validate controls form validation
	AttrValidate = "hx-validate"
	// Prompt shows a prompt before submitting
	AttrPrompt = "hx-prompt"
	// On (base attribute - use On() function for specific events)
	AttrOn = "hx-on"
)

Variables

This section is empty.

Functions

func On

func On(event string) string

On returns a formatted hx-on attribute key for the given event. It accepts both standard DOM events (click, change, etc.) and htmx events.

Examples:

  • On("click") returns "hx-on:click"
  • On("htmx:config-request") returns "hx-on:htmx:config-request"

func Script

func Script() h.Node

Script returns a script element containing the embedded htmx library. This can be placed in the document head to enable htmx functionality.

Example:

Head(hx.Script())

Types

type DOMEvent

type DOMEvent = string

DOMEvent represents standard browser/DOM events that can be used with hx-on.

const (
	// Click is fired when the user clicks on an element
	Click DOMEvent = "click"
	// Dblclick is fired when the user double-clicks on an element
	Dblclick DOMEvent = "dblclick"
	// Mouseover is fired when the mouse pointer enters an element
	Mouseover DOMEvent = "mouseover"
	// Mouseout is fired when the mouse pointer leaves an element
	Mouseout DOMEvent = "mouseout"
	// Mouseenter is fired when the mouse pointer enters an element (doesn't bubble)
	Mouseenter DOMEvent = "mouseenter"
	// Mouseleave is fired when the mouse pointer leaves an element (doesn't bubble)
	Mouseleave DOMEvent = "mouseleave"
	// Mousedown is fired when a mouse button is pressed on an element
	Mousedown DOMEvent = "mousedown"
	// Mouseup is fired when a mouse button is released on an element
	Mouseup DOMEvent = "mouseup"
	// Mousemove is fired when the mouse pointer moves over an element
	Mousemove DOMEvent = "mousemove"
	// Keydown is fired when the user presses a key
	Keydown DOMEvent = "keydown"
	// Keyup is fired when the user releases a key
	Keyup DOMEvent = "keyup"
	// Keypress is fired when the user presses a character key
	Keypress DOMEvent = "keypress"
	// Submit is fired when a form is submitted
	Submit DOMEvent = "submit"
	// Change is fired when the value of an element has been changed
	Change DOMEvent = "change"
	// Input is fired when the value of an element has been changed (immediately for inputs)
	Input DOMEvent = "input"
	// Focus is fired when an element gets focus
	Focus DOMEvent = "focus"
	// Blur is fired when an element loses focus
	Blur DOMEvent = "blur"
	// Focusin is fired when an element is about to get focus
	Focusin DOMEvent = "focusin"
	// Focusout is fired when an element is about to lose focus
	Focusout DOMEvent = "focusout"
	// Load is fired when the page has finished loading (prefixed to avoid collision with htmx:load)
	Load DOMEvent = "load"
	// Unload is fired when the page is being unloaded (prefixed to avoid collision with htmx events)
	Unload DOMEvent = "unload"
	// Resize is fired when the browser window is resized
	Resize DOMEvent = "resize"
	// Scroll is fired when an element's scrollbar is being scrolled
	Scroll DOMEvent = "scroll"
	// Select is fired when the user selects some text
	Select DOMEvent = "select"
	// Error is fired when an error occurs loading an external file
	Error DOMEvent = "error"
	// Contextmenu is fired when the user right-clicks on an element
	Contextmenu DOMEvent = "contextmenu"
	// Wheel is fired when the mouse wheel rolls up or down
	Wheel DOMEvent = "wheel"
	// Touchstart is fired when a finger touches the touch surface
	Touchstart DOMEvent = "touchstart"
	// Touchmove is fired when a finger moves on the touch surface
	Touchmove DOMEvent = "touchmove"
	// Touchend is fired when a finger is removed from the touch surface
	Touchend DOMEvent = "touchend"
	// Touchcancel is fired when a touch is interrupted
	Touchcancel DOMEvent = "touchcancel"
	// Drag is fired when an element is being dragged
	Drag DOMEvent = "drag"
	// Dragstart is fired when the user starts dragging an element
	Dragstart DOMEvent = "dragstart"
	// Dragend is fired when the user has finished dragging
	Dragend DOMEvent = "dragend"
	// Dragenter is fired when the dragged element enters a drop target
	Dragenter DOMEvent = "dragenter"
	// Dragleave is fired when the dragged element leaves a drop target
	Dragleave DOMEvent = "dragleave"
	// Dragover is fired when the dragged element is over a drop target
	Dragover DOMEvent = "dragover"
	// Drop is fired when the dragged element is dropped on a drop target
	Drop DOMEvent = "drop"
	// Animationstart is fired when a CSS animation has started
	Animationstart DOMEvent = "animationstart"
	// Animationend is fired when a CSS animation has completed
	Animationend DOMEvent = "animationend"
	// Animationiteration is fired when a CSS animation is repeated
	Animationiteration DOMEvent = "animationiteration"
	// Transitionstart is fired when a CSS transition has started
	Transitionstart DOMEvent = "transitionstart"
	// Transitionend is fired when a CSS transition has ended
	Transitionend DOMEvent = "transitionend"
	// Transitionrun is fired when a CSS transition begins running
	Transitionrun DOMEvent = "transitionrun"
)

type HtmxEvent

type HtmxEvent = string

HtmxEvent represents htmx-specific events

const (
	// HtmxAbort is fired when a request is aborted
	HtmxAbort HtmxEvent = "htmx:abort"
	// HtmxAfterOnLoad is fired after the onLoad method
	HtmxAfterOnLoad HtmxEvent = "htmx:after-on-load"
	// HtmxAfterProcessNode is fired after processing a node
	HtmxAfterProcessNode HtmxEvent = "htmx:after-process-node"
	// HtmxAfterRequest is fired after a request completes
	HtmxAfterRequest HtmxEvent = "htmx:after-request"
	// HtmxAfterSettle is fired after settling
	HtmxAfterSettle HtmxEvent = "htmx:after-settle"
	// HtmxAfterSwap is fired after swapping
	HtmxAfterSwap HtmxEvent = "htmx:after-swap"
	// HtmxBeforeCleanupElement is fired before cleaning up an element
	HtmxBeforeCleanupElement HtmxEvent = "htmx:before-cleanup-element"
	// HtmxBeforeOnLoad is fired before onLoad
	HtmxBeforeOnLoad HtmxEvent = "htmx:before-on-load"
	// HtmxBeforeProcessNode is fired before processing a node
	HtmxBeforeProcessNode HtmxEvent = "htmx:before-process-node"
	// HtmxBeforeRequest is fired before a request
	HtmxBeforeRequest HtmxEvent = "htmx:before-request"
	// HtmxBeforeSend is fired before sending a request
	HtmxBeforeSend HtmxEvent = "htmx:before-send"
	// HtmxBeforeSwap is fired before swapping
	HtmxBeforeSwap HtmxEvent = "htmx:before-swap"
	// HtmxConfigRequest is fired when configuring a request
	HtmxConfigRequest HtmxEvent = "htmx:config-request"
	// HtmxConfirm is fired when confirming an action
	HtmxConfirm HtmxEvent = "htmx:confirm"
	// HtmxHistoryCacheError is fired on history cache error
	HtmxHistoryCacheError HtmxEvent = "htmx:history-cache-error"
	// HtmxHistoryCacheMiss is fired on history cache miss
	HtmxHistoryCacheMiss HtmxEvent = "htmx:history-cache-miss"
	// HtmxHistoryCacheMissError is fired on history cache miss error
	HtmxHistoryCacheMissError HtmxEvent = "htmx:history-cache-miss-error"
	// HtmxHistoryRestore is fired when restoring history
	HtmxHistoryRestore HtmxEvent = "htmx:history-restore"
	// HtmxBeforeHistorySave is fired before saving history
	HtmxBeforeHistorySave HtmxEvent = "htmx:before-history-save"
	// HtmxLoad is fired when htmx loads
	HtmxLoad HtmxEvent = "htmx:load"
	// HtmxNoSSESourceError is fired when no SSE source is found
	HtmxNoSSESourceError HtmxEvent = "htmx:no-sse-source-error"
	// HtmxOnLoadError is fired on load error
	HtmxOnLoadError HtmxEvent = "htmx:on-load-error"
	// HtmxOobAfterSwap is fired after OOB swap
	HtmxOobAfterSwap HtmxEvent = "htmx:oob-after-swap"
	// HtmxOobBeforeSwap is fired before OOB swap
	HtmxOobBeforeSwap HtmxEvent = "htmx:oob-before-swap"
	// HtmxOobErrorNoTarget is fired when OOB has no target
	HtmxOobErrorNoTarget HtmxEvent = "htmx:oob-error-no-target"
	// HtmxPrompt is fired when showing a prompt
	HtmxPrompt HtmxEvent = "htmx:prompt"
	// HtmxPushedIntoHistory is fired when pushed into history
	HtmxPushedIntoHistory HtmxEvent = "htmx:pushed-into-history"
	// HtmxResponseError is fired on response error
	HtmxResponseError HtmxEvent = "htmx:response-error"
	// HtmxSendError is fired on send error
	HtmxSendError HtmxEvent = "htmx:send-error"
	// HtmxSseError is fired on SSE error
	HtmxSseError HtmxEvent = "htmx:sse-error"
	// HtmxSseOpen is fired when SSE opens
	HtmxSseOpen HtmxEvent = "htmx:sse-open"
	// HtmxSwapError is fired on swap error
	HtmxSwapError HtmxEvent = "htmx:swap-error"
	// HtmxTargetError is fired on target error
	HtmxTargetError HtmxEvent = "htmx:target-error"
	// HtmxTimeout is fired on request timeout
	HtmxTimeout HtmxEvent = "htmx:timeout"
	// HtmxValidationValidate is fired when validating
	HtmxValidationValidate HtmxEvent = "htmx:validation:validate"
	// HtmxValidationFailed is fired when validation fails
	HtmxValidationFailed HtmxEvent = "htmx:validation:failed"
	// HtmxValidationHalted is fired when validation is halted
	HtmxValidationHalted HtmxEvent = "htmx:validation:halted"
	// HtmxXhrAbort is fired when XHR is aborted
	HtmxXhrAbort HtmxEvent = "htmx:xhr:abort"
	// HtmxXhrLoadend is fired when XHR load ends
	HtmxXhrLoadend HtmxEvent = "htmx:xhr:loadend"
	// HtmxXhrLoadstart is fired when XHR load starts
	HtmxXhrLoadstart HtmxEvent = "htmx:xhr:loadstart"
	// HtmxXhrProgress is fired during XHR progress
	HtmxXhrProgress HtmxEvent = "htmx:xhr:progress"
)

type ModifierValue

type ModifierValue = string

ModifierValue represents trigger modifiers

const (
	// ModifierOnce triggers only once
	ModifierOnce ModifierValue = "once"
	// ModifierChanged triggers only if value changed
	ModifierChanged ModifierValue = "changed"
	// ModifierDelay adds a delay
	ModifierDelay ModifierValue = "delay"
	// ModifierThrottle throttles events
	ModifierThrottle ModifierValue = "throttle"
	// ModifierFrom specifies event source
	ModifierFrom ModifierValue = "from"
	// ModifierTarget specifies event target
	ModifierTarget ModifierValue = "target"
	// ModifierConsume consumes the event
	ModifierConsume ModifierValue = "consume"
	// ModifierQueue queues events
	ModifierQueue ModifierValue = "queue"
)

type ParamsValue

type ParamsValue = string

ParamsValue represents params filter values

const (
	// ParamsAll includes all parameters (default)
	ParamsAll ParamsValue = "*"
	// ParamsNone excludes all parameters
	ParamsNone ParamsValue = "none"
)

type RequestValue

type RequestValue = string

RequestValue represents request configuration values

const (
	// RequestTimeout sets timeout
	RequestTimeout RequestValue = "timeout"
	// RequestCredentials includes credentials
	RequestCredentials RequestValue = "credentials"
	// RequestNoHeaders excludes headers
	RequestNoHeaders RequestValue = "noHeaders"
)

type SwapValue

type SwapValue = string

SwapValue represents valid values for hx-swap attribute

const (
	// SwapInnerHTML swaps the inner HTML of the target (default)
	SwapInnerHTML SwapValue = "innerHTML"
	// SwapOuterHTML swaps the entire target element with the response
	SwapOuterHTML SwapValue = "outerHTML"
	// SwapBeforeBegin inserts the response before the target
	SwapBeforeBegin SwapValue = "beforebegin"
	// SwapAfterBegin inserts the response at the beginning of the target
	SwapAfterBegin SwapValue = "afterbegin"
	// SwapBeforeEnd inserts the response at the end of the target
	SwapBeforeEnd SwapValue = "beforeend"
	// SwapAfterEnd inserts the response after the target
	SwapAfterEnd SwapValue = "afterend"
	// SwapDelete deletes the target regardless of the response
	SwapDelete SwapValue = "delete"
	// SwapNone does not append content from the response
	SwapNone SwapValue = "none"
)

type SyncValue

type SyncValue = string

SyncValue represents sync strategy values

const (
	// SyncDrop drops the request
	SyncDrop SyncValue = "drop"
	// SyncAbort aborts the existing request
	SyncAbort SyncValue = "abort"
	// SyncReplace replaces the existing request
	SyncReplace SyncValue = "replace"
	// SyncQueue queues the request
	SyncQueue SyncValue = "queue"
)

type TriggerValue

type TriggerValue = string

TriggerValue represents common trigger values

const (
	// TriggerClick triggers on click
	TriggerClick TriggerValue = "click"
	// TriggerChange triggers on change
	TriggerChange TriggerValue = "change"
	// TriggerSubmit triggers on submit
	TriggerSubmit TriggerValue = "submit"
	// TriggerLoad triggers on page load
	TriggerLoad TriggerValue = "load"
	// TriggerReveal triggers when element is scrolled into view
	TriggerReveal TriggerValue = "revealed"
	// TriggerIntersect triggers when element intersects viewport
	TriggerIntersect TriggerValue = "intersect"
	// TriggerOnce triggers only once
	TriggerOnce TriggerValue = "once"
	// TriggerDefault triggers with default behavior
	TriggerDefault TriggerValue = "default"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL