Replies: 1 comment 1 reply
-
You can't use x-model on a file input, because their semantics are just totally different from many other input types. You can handle the change event to get the files into your component, and bind files to the input if needed. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using https://tetraframework.com, which internally uses Alpine.js for creating components. I'm not completely sure if the bug I am experiencing is a Tetra bug or an Alpine one, but as I can't find the bug in Tetra, it seems to be more generic.
Tetra creates Alpine.js components on the fly, and uses
x-model
data bindings, e.g. here (I tried to snip away everything that is not needed):When loading the page with this component (there are many other inputs), I get an error in the console:
The error occurs in the end of the function bindInputValue():
alpine/packages/alpinejs/src/utils/bind.js
Line 78 in ab743bc
The direct assignment of any value to
el.value
is forbidden (due to security reasons).So I think that, for file inputs, Alpine has to create another if/else branch (analogue to selects, checkbox, boolean etc).
I am not capable of doing this, as my Js knowledge is only limited.
Maybe Tetra has to produce some code that prevents creating a
x-model
attr in a file type input - but I wanted to ask here if anyone sees this too as a bug in Alpine.I can make the error message disappear by adding an empty clause:
But I don't know all the impacts this will produce.
Beta Was this translation helpful? Give feedback.
All reactions