-
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 <div
tetra-component="common__default__profile_master_data_editor"
x-bind="__rootBind"
...
x-data="common__default__profile_master_data_editor('{...snip...}')"
>
<form enctype="multipart/form-data">
<input type="file" name="avatar" class="form-control" accept="image/*" x-model="avatar" id="id_avatar">
<button @click="submit()">Save</button>
</form>
</div> 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(): The direct assignment of any value to 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. I can make the error message disappear by adding an empty clause: ...
} else if (el.type === "file") {
// do nothing.
} else {
... But I don't know all the impacts this will produce. |
Beta Was this translation helpful? Give feedback.
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.
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.