I have a form with f.file_field tag:
<div class="forming">
<%= simple_form_for @product do |f| %>
<%= f.file_field :photos, multiple: true, name: "product[photos]" %>
<%= f.hidden_field :photos_cache %>
<%= f.button :submit, class: "btn-primary" %>
<% end %>
</div>
I have a JS script, that tries to store the files selected by the user into a window variable:
<script>
const productPhotos = document.getElementById("product_photos");
const updateInputFiles = (e) => {
const input = e.target;
if (window.postFiles != undefined) {
console.log(window.postFiles);
window.postFiles = $.merge(window.postFiles, input.files);
console.log(window.postFiles);
} else {
window.postFiles = input.files;
}
}
productPhotos.addEventListener("change", updateInputFiles)
</script>
I console log the window.postFiles before the merge and after, but the value does not change.
Can someone help me? How can I use ES6 to achieve the same?
Thanks a lot in advance.