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

support this: extended css selector #2326

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

gbourant
Copy link
Contributor

@gbourant gbourant commented Feb 16, 2024

hx-trigger now supports this as extended css selector, so we can do something like this:

<form method="GET" hx-trigger="input delay:500ms changed from:(this input), submit">
        <input type="email" name="email">
        <input name="password">
</form>

Also we might want to do thisFirst (or something like that) which will use .querySelector. (We can do this with :first-child/:last-child/:nth-child)

If this is about to be added i will add the tests later.

@Telroshan
Copy link
Collaborator

What is the difference / added value compared to the already existing find keyword?

@gbourant
Copy link
Contributor Author

The form has two input fields, if i use from:(find input) the find method returns only the first. That is happening because the find method uses .querySelector and not .querySelectorAll

In order to get the all input fields i use from:(this input) which uses .querySelectorAll.

@Telroshan
Copy link
Collaborator

Telroshan commented Feb 26, 2024

Oh ok indeed I see, I also complained back then about the inability to target multiple elements with the from modifier (#1597)

  • I must admit I'm not fond of the this keyword in this case, doesn't sound that intuitive to me.
  • Please note that we're holding off feature PRs for now as we work on htmx 2, which we're hoping to release in beta by early March
  • As per the contribution guidelines, we expect people to respect the PR template, including referencing an associated issue (we don't take unsollicited feature PRs - note that this relates directly to Rework "find" extended CSS selector #1597 so you don't need to create a new issue don't worry, but I'll have to have 1cg look at the issue first before a PR can be accepted on the matter), and tests (so don't hesitate adding tests to your PRs directly to speed up the back-and-forth)
  • Also please note that as this PR would add a keyword, you'd have to update the docs accordingly to reflect the changes

Until then, as a workaround, note that you can put an ID or use any specific-enough selector to target elements within your form, such as

<form id="whatever" method="GET" hx-trigger="input delay:500ms changed from:(#whatever input), submit">
        <input type="email" name="email">
        <input name="password">
</form>

As said above, we aren't going to move forward with feature PRs until we get htmx 2.0 out so don't expect movement from our side on this before at least early April I'd say

@Telroshan Telroshan added the enhancement New feature or request label Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants