Skip to content

Add local data.* access and deletion to hx-live - #3931

Open
scriptogre wants to merge 2 commits into
bigskysoftware:four-devfrom
scriptogre:4.0/hx-live-data-proxy
Open

Add local data.* access and deletion to hx-live#3931
scriptogre wants to merge 2 commits into
bigskysoftware:four-devfrom
scriptogre:4.0/hx-live-data-proxy

Conversation

@scriptogre

@scriptogre scriptogre commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Why

Before:

<section data-count="10">
    <button id="save" hx-on:click="
        console.log(
            data.count,            // -> 10 from <section>
            q('#save').data.count  // -> 10 from <section>
        )
    ">Save</button>
</section>

After:

<section data-count="10">
    <button id="save" hx-on:click="
        console.log(
            data.count,            // -> 10 from <section>
            q(this).data.count,       // -> undefined on <button>
            q('#save').data.count  // -> undefined on #save
        )
    ">Save</button>
</section>

Changes

  1. Read and write data-* attributes in three ways:

    data.count            // this element, then its ancestors
    q(this).data.count       // this element only
    q('#cart').data.count // #cart only
  2. Use delete to remove an attribute:

    delete data.count            // remove the closest data-count
    delete q(this).data.count       // remove data-count from this
    delete q('#cart').data.count // remove data-count from #cart

    null is a stored JSON value:

    data.result = null // write data-result="null"
    data.result        // null

Related to #3928. Either PR can merge first.

@scriptogre scriptogre added htmx 4 Issues specific to htmx version 4 hx-live labels Jul 30, 2026
@scriptogre
scriptogre force-pushed the 4.0/hx-live-data-proxy branch from 89e68be to a59e25e Compare July 30, 2026 20:48
@scriptogre scriptogre changed the title Add local data.* state to hx-live Addthis.data.* to hx-live Jul 30, 2026
@scriptogre scriptogre changed the title Addthis.data.* to hx-live Add this.data.* to hx-live Jul 30, 2026
@scriptogre scriptogre changed the title Add this.data.* to hx-live Update data.* in hx-live Jul 30, 2026
@scriptogre scriptogre changed the title Update data.* in hx-live Update data.* behaviour in hx-live Jul 30, 2026
@scriptogre scriptogre changed the title Update data.* behaviour in hx-live Update data.* in hx-live Jul 30, 2026
@scriptogre
scriptogre force-pushed the 4.0/hx-live-data-proxy branch from a59e25e to aab3f04 Compare July 30, 2026 22:08
@scriptogre
scriptogre force-pushed the 4.0/hx-live-data-proxy branch from aab3f04 to e2fd5c7 Compare July 30, 2026 22:45
@scriptogre scriptogre changed the title Update data.* in hx-live Add local data.* access and deletion to hx-live Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

htmx 4 Issues specific to htmx version 4 hx-live

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant