Replies: 2 comments
-
I've had another idea. There's actually no need to use event listeners at all to show or hide the progress bar. I can just use CSS to show it when the file input element has the .htmx-request class set, like so: input[type='file'] ~ progress {
display: none;
}
input[type='file'].htmx-request ~ progress {
display: block;
} (Note: This doesn't really work in the minimal example about because But that's just an aside. I'd still like to know why the event is fired twice. |
Beta Was this translation helpful? Give feedback.
-
Hey, that doesn't sound normal indeed Looking at the code, I see this Lines 4526 to 4533 in 07d3518 Looks like this part of the code has been here for quite a long time (added in this 2020 commit : 3b115c0) I would imagine that it was added to make sure that XMLHTTPRequests making an upload would properly fire events, but this might end up in double calls if both the request and its Just a gut guess though If you are interested, please feel free to open an actual GitHub issue for that & investigate it! Bugfix PRs are highly appreciated |
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
I'm trying to implement a file upload with a progress bar. The progress bar should be hidden until the user starts the upload.
I've tried to add a listener for the
htmx:xhr:loadstart
event, use thehtmx:xhr:progress
event to update the progress bar and hide it again onhtmx:xhr:loadend
(or...:abort
).Weirdly though, the
loadstart
event seems to fire twice on the file input element and I don't see why. Here's a minimal example to reproduce the behaviour:Am I missing something? It actually fires twice on the exact same element (
#fileUpload
). Should I perhaps not usehtmx:xhr:loadstart
buthtmx:configRequest
for this?Beta Was this translation helpful? Give feedback.
All reactions