mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-30 14:31:47 +00:00
See HTMX base repo
Changes in this fork
Fixes
- Fix outerHTML swap if parent is null (i.e. too fast clicking for example) : an error would be fired trying to access the parent's properties and block further interactions with the element => now ignored when parent is null
- The
checked
attribute is used instead of thevalue
attribute for checkbox inputs, when building the request payload, which can then correctly be parsed as a boolean by the backend - Unchecked checkboxes aren't excluded anymore from request payload (I needed this for PATCH requests for example)
- Fix target and source elements sent to
selectAndSwap
during the SSE swapping process that were inverted in the original code, now allowing to properly usehx-target
for example to specify which element to swap with SSE
Changes
- The htmx-indicator is not hidden on request's response if the response has a
HX-Redirect
header set (just a personal visual preference) - If the target specified to
htmx.ajax()
(and so thetargetOverride
passed toissueAjaxRequest()
) can't be found, an error is thrown (instead of the HTMX default implementation that crawls the hierarchy to find the firsthx-target
specified on a parent element as a fallback) - In the default HTMX implementation, elements that have an ID have a special treatment during swapping ; if an element with an ID is about to be inserted, and to replace another element with the same ID, for a reason I ignore, HTMX clones the old elements "settling attributes" (that are, by default,
class
,style
,width
&height
) into the new element, then restores the new element initial attributes after the settling. My problem with this ; using a MutationObserver to apply style to newly added nodes (for example a line that should be positionned at current local time with a line of JS in a calendar) results in those modifications being reverted by HTMX after the settling. Since this cloning step appears useless to me (maybe am I wrong though ?), I got rid of it here, as well as theattributesToSettle
property that was only used for that purpose. - When an HTMX error is logged, the
detail
context object passed along in the internal functions is now included in the log, for an easier debugging. This way, ahx-targetError
for example, will also log the actual target that HTMX was trying to retrieve. - The attribute
hx-push-url
is no longer inherited by default by children elements. You can specifyhx-push-url="inherit"
on children elements though, to inherit the value from the closest parent that defines ahx-push-url
.
Additions
hx-error-target
andhx-error-swap
attributes to allow swapping server's reponse on error (i.e request with astatus >= 300
). Those attributes behave exactly like, respectively, hx-target and hx-swaphx-sse-swap
attribute to overridehx-swap
attribute's value for SSE swapping, ie to allow an element to have different swapping behaviours for requests responses & for SSE. Please note thathx-swap
is used as a fallback in casehx-sse-swap
is not defined, so this attribute should only be used when necessary, ie to split swapping behaviours apart.- The HX-Trigger header in server's response supports a comma-and-space-separated event names list, to send multiple events to trigger without data, and without having to use a JSON format. Sending for example the header
HX-Trigger: myEvent, myOtherEvent
would trigger both the eventsmyEvent
andmyOtherEvent
on the client - The event sources array (SSE) is now exposed in the htmx API, so client can add eventListeners to the same sources created by htmx with the hx-sse attribute
htmx.ajax()
supports an additional propertyswap
in thecontext
argument, to override the swapping behaviour. This argument must be a string and follows the syntax of the attributehx-swap
- The
htmx:beforeOnLoad
,htmx:beforeSwap
,htmx:afterSwap
,htmx:afterSettle
,htmx:swapError
,htmx:afterRequest
,htmx:afterOnLoad
,htmx:onLoadError
events are now passed an additional propertyisError
in the event'sdetail
property, which indicates if the request's response has an error status (ie a code >= 400)
Description
Languages
JavaScript
92%
HTML
7.1%
CSS
0.4%
TypeScript
0.3%
Ruby
0.1%