You are viewing limited content. For full access, please sign in.

Question

Question

javascript to remove files from upload field (repost hoping for a solution)

asked on October 1, 2020

Trying to execute a bit of javascript to delete the files in an Upload field, and then save the empty field as updated to the Forms db when the form is submitted.

Assume we have a field "Upload1" with selector #q1, and it has a file(s) saved into it from a previous step in the process.  Upon loading the form for a later step, if we execute a remove on the files table with "$('#q1 table.files>tbody>tr').remove();", it appears to work in so much as the files are no longer shown in that field.  But, when the form is submitted, the files remain part of the instance in the database - the empty upload field does not overwrite the previous files.

If we take a different approach and act on the file delete button (the "X" at the end of the row) with "$('#q1 .file-del').trigger('click');" that does work, but it kicks off the confirmation modal which requires the user to click "Delete" in the confirmation box.  This is not acceptable, as we want the field to clear with javascript and no user action, and I don't know of a way to bypass the modal.

Any ideas?

0 0

Replies

replied on October 2, 2020

All I would say is have another .trigger('click') that click the 'ok' on the delete confirmation box. All that seems messy. Another thing to investigate is what are the negative impacts of deleting the column from the database? Exactly what do you need to delete? 

I bet @████████ has been down this road before. He is a ninja when it comes to this stuff.

 

0 0
replied on October 6, 2020

Thanks Chris.  The form/process I am implementing involves multiple Upload fields that are conditional and need to cleared, so attempting "click" triggers for the "Delete" button and the modal "OK" buttons would indeed be messy and not really meet the need.  I will continue searching for better solution.

0 0
replied on October 2, 2020
0 0
replied on October 6, 2020 Show version history

Thanks Steve. I had already found that article and tried the code example, but my use case involves clearing files from the Upload fields in a subsequent form edit session after the form has been saved with a file attachment on the Upload field.  In that case, the code in the referenced article did not seem to do the trick.  Will keep looking for a solution.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.