Giter VIP home page Giter VIP logo

Comments (4)

pfiadDi avatar pfiadDi commented on September 17, 2024 1

Thank you - maybe I'll give it a try. Would be interesting to learn more about htmx by trying ...
Edit:
The bug prevails also when the elements are inside the form and there is a normal click trigger (without modifier) on the form element.

Edit 2: @Telroshan you are right. When I change this function to return false the elements work as expected.

from htmx.

Telroshan avatar Telroshan commented on September 17, 2024

Hey, I'm not sure I understand the issue here.

See this JSFiddle, I copied your example above and added for ex a <div hx-get="/test" hx-trigger="click[event.target.matches('button#btnid')] from:body">

When I click the button, a request is correctly fired, and the date input + checkbox correctly work for me, did I miss something?

from htmx.

pfiadDi avatar pfiadDi commented on September 17, 2024

Hey @Telroshan , I am sorry I haven't seen your reply earlier. And my example code was trashed by github.
This was my original example:
https://jsfiddle.net/et4j60bp/

I can confirm, when a div is triggered it works but in my example I tried to trigger a form - in this case it doesn't work.

(in my app I have fields outside of a form and store selected values in a form with hidden inputs - after click on some elements I want to trigger the form) in this case the bug arises.

For now I was able to avoid it by triggering my form via JS and removing the hx-trigger element from the form.

from htmx.

Telroshan avatar Telroshan commented on September 17, 2024

Ooooh ok I understand now, thanks for the JSFiddle @pfiadDi.

Seems to be an unhandled specifity of the from modifier indeed ; I can see in htmx's code that the function determining whether an event should be default prevented checks this:

htmx/src/htmx.js

Lines 2307 to 2315 in 0f70de7

function shouldCancel(evt, node) {
const elt = asElement(node)
if (!elt) {
return false
}
if (evt.type === 'submit' || evt.type === 'click') {
if (elt.tagName === 'FORM') {
return true
}

The issue here being that the we indeed have a click event, and the element against which the tag name is checked, is the form itself and not the element that triggered the event (which would here be the date or checkbox input).
So, in this case, event.preventDefault is called, which explains why the inputs don't work anymore ; their native behavior has been canceled by htmx.

In the JSFiddle that you sent, we can confirm this by changing the form tag to a div and suddenly the inputs work again 😅
So, it definitely looks like a bug to me; feel free to open a bugfix PR if you feel like it!

My gut guess would be that we could simply need to check the tag name of the event's target instead of the listening element itself. Though, will it be enough, and won't it break any other behavior ? The test suite will tell us!

from htmx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.