Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite the HX-Retarget header to use extended query selectors #2017

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

itepastra
Copy link
Contributor

Description

I modified the HX-Retarget header handling to use extended css selectors.

Corresponding issue:
#1962

Testing

I made a quick webserver and html site using golang echo.

package main

import (
	"github.com/labstack/echo/v4"
)

func main() {
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.File("idx.html")
	})
	e.GET("/htmx", func(c echo.Context) error {
		return c.File("../../htmx/src/htmx.js")
	})
	e.POST("/changethis", func(c echo.Context) error {
		c.Response().Header().Add("HX-Retarget", "this")
		return c.String(200, "changed")
	})
	e.POST("/changehi", func(c echo.Context) error {
		c.Response().Header().Add("HX-Retarget", "#hi")
		return c.String(200, "bye")
	})
	e.POST("/changepreviousp", func(c echo.Context) error {
		c.Response().Header().Add("HX-Retarget", "previous p")
		return c.String(200, "prev")
	})
	e.POST("/changenextp", func(c echo.Context) error {
		c.Response().Header().Add("HX-Retarget", "next p")
		return c.String(200, "next")
	})
	e.Logger.Fatal(e.Start(":1323"))
}

with the index page

<!DOCTYPE html>
<html lang="en">

<head>
    <title>hxtest</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="css/style.css" rel="stylesheet">
    <script src="htmx"></script>
</head>

<body>
    <div id="hi">
        hi
    </div>
    <p>1</p>
    <p>2</p>


    <button hx-post="changethis">
        click
    </button>
    <button hx-post="changehi">
        change hi
    </button>
    <button hx-post="changenextp">
        change next
    </button>
    <button hx-post="changepreviousp">
        change previous
    </button>
    <p>3</p>
    <p>4</p>
</body>

</html>

I then tested the buttons and they worked as expected

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@alexpetros alexpetros added the ready for review Issues that are ready to be considered for merging label Dec 20, 2023
@1cg 1cg merged commit 1f4903c into bigskysoftware:dev Dec 20, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Issues that are ready to be considered for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants