simsalabim/sisyphus

Input arrays not saving properly...

Opened this issue · 1 comments

Really interested in using this wonderful plugin to save draft email messages for a mailing interface I'm putting together for a non-profit cooperative.

Most everything is working as expected except one set of inputs that don't seem to save properly. When a user uploads documents to attach to their email, they're stored on the server via ajax upload and input fields like below are dynamically appended to the form:

<input type="hidden" name="attached_files[]" id="attached_file_0" value="file1.gif">
<input type="hidden" name="attached_files[]" id="attached_file_1" value="file2.gif">
<input type="hidden" name="attached_files[]" id="attached_file_2" value="file3.gif">

These are also recorded in a database table of draft messages so that when the page is reloaded (even from another computer) the files are shown as still being attached etc.

When I call sisyphus on the loaded email form like $("#emailForm").sisyphus(); it rewrites the attached_files[] input array as follows:

<input type="hidden" name="attached_files[]" id="attached_file_0" value="file3.gif">
<input type="hidden" name="attached_files[]" id="attached_file_1" value="file3.gif">
<input type="hidden" name="attached_files[]" id="attached_file_2" value="file3.gif">

Obviously it's interpreting the last discovered input with that name and assigning all similarly named inputs with the same value.

It does this when the page is loaded fresh from the server and the input array isn't even loaded dynamically. The inputs start out fine but once sisyphus is called on the form they all get the same value.

I could work around it by storing the attached_files as a delimited list of files in a single input but wanted to check and see if this is a known limitation or perhaps I'm just missing something obvious (wouldn't be the first time!).

Thank you for all the hard work you've put into this amazing plugin and let me know if there's any more information I can provide.

-b

@PsychProd thanks for reporting. Clearly this use case was not taken into account.