So, I am trying to use live_file_input in which I have the following scenario:
Category1
Category2
Category3
Category4
In each category, which is an accordion view, the user can add an upload.
So, for each accordion, I have an input form with a separate id on each form, and a hidden input field to convey the data.
However, when the image from category 3 is uploaded, the
validate-form handler gets the hidden input from category 1.
I’d like to figure out how to EITHER:
Correctly associate the parameters to the validate event handler with the form it is coming from,
OR
Directly pass the id of the category with the upload event.
The image uploading all works fine, the problem is associating c.id with the image once it is delivered.
Note that this in a sub-component in which the parent @uploads.image has been passed in as @upload.
This is the code that is iterated on.
<form
id={"upload-cimg-" <> to_string(c.id)}
phx-submit="save-classifier-img"
phx-change="validate-classifier-img"
>
<div phx-drop-target={@upload.ref} class="items-center text-center">
<span class="block">Add a reference image:</span>
<label for={@upload.ref}>
<div class="h20 w20">
<.icon name="hero-plus-circle" class="h-20 w-20 mt-2 text-gray-400" />
</div>
</label>
</div>
<input type="hidden" name="cid" value={c.id} />
<.live_file_input upload={@upload} class="hidden" />
</form>