-
Hello, I am trying to build a file upload component using dropzone.js My code is below (details removed for brevity)
The code works fine when i have just one such component in the page. Same code used to work correctly with htmx v 1.5.0, but is giving error with htmx v 1.6.1. Please advise. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, script tags are now evaluated the "normal" way, that is the way that they would be interpreted if you have them in a regular web page, so variables at the top level will be global. To deal with this you need to introduce a new scope, for example by wrapping everything in a function: (function(){
//***** The line below gives error when more than one component is in the page ******//
let fdz = document.getElementById("fdz_<%= @block.id %>")
//More code implementing dropzone js
)() This wraps all the code in a function and then invokes the function, shielding the top level scope from your variables. |
Beta Was this translation helpful? Give feedback.
Yes, script tags are now evaluated the "normal" way, that is the way that they would be interpreted if you have them in a regular web page, so variables at the top level will be global.
To deal with this you need to introduce a new scope, for example by wrapping everything in a function:
This wraps all the code in a function and then invokes the function, shielding the top level scope from your variables.