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

previous input not work as expected. #2610

Closed
zw963 opened this issue Jun 12, 2024 · 2 comments
Closed

previous input not work as expected. #2610

zw963 opened this issue Jun 12, 2024 · 2 comments

Comments

@zw963
Copy link

zw963 commented Jun 12, 2024

Plese check following example, there are two input element which has same name.

<input type="hidden" value="WAnUI0ZhE8Gdab2pVgFPPDG-6Av7NuIdmXDlY_z08xQ" name="_csrf">
....
<label>
  <input type="hidden" name="university:marked" value="false" id="marked_unmark">
  <input type="checkbox" name="university:marked" value="true" id="marked" hx-put="/universities/812" hx-swap="none" hx-indicator="#spinner" hx-include="[name='_csrf'],previous input" class="">
  <span>标记</span>
</label>

The previous input not work in above include attribute, it not includes the hidden input elements which above it,
and cause university:marked set to false is not available when user uncheck the checkbox.

It not work if i move hidden input after the checkbox input, and use next input too.

But, if use #id selector instead, it work as expected as following code:

<input type="hidden" value="WAnUI0ZhE8Gdab2pVgFPPDG-6Av7NuIdmXDlY_z08xQ" name="_csrf">
....
<label>
  <input type="hidden" name="university:marked" value="false" id="marked_unmark">
  <input type="checkbox" name="university:marked" value="true" id="marked" hx-put="/universities/812" hx-swap="none" hx-indicator="#spinner" hx-include="[name='_csrf'],input#marked_unmark" class="">
  <span>标记</span>
</label>

** Version

htmx 1.9.12
hyperscript 0.9.12

Thanks

@Telroshan
Copy link
Collaborator

Telroshan commented Jun 15, 2024

Hey, unfortunately it's indeed a weakness of our extended selectors syntax at the moment. It's only handled if it's the only selector, i.e:

  • previous input will work
  • But div, previous input won't, and will simply result in a document.querySelectorAll("div, previous input"), which of course won't retrieve the element you're looking for

That's a weakness we'll have to fix in the future, and for now you may indeed use this ID workaround (or any standard CSS selector) that you already found out!

@Telroshan
Copy link
Collaborator

Closing this, as multiple extended selectors support was added in #2902, released alongside htmx 2.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants