When autofilling file fields, allow not changing filename from previous submission

Created on 13 February 2023, over 1 year ago
Updated 11 June 2023, about 1 year ago

Problem/Motivation

When using the autofill feature and a new submission NEW is autofilled with the data from the user's previous submission PREV, any files from the PREV submission are renamed according to the rules in the File Name Pattern field. If the File Name Pattern field uses tokens, this can cause the PREV submission's filename to change.

For example, if the File Name Pattern contains a token to include the submission ID, the filename will be updated to contain the NEW submission's ID and it will no longer contain the PREV submission's ID.

In my own case, user's are filling out a form every year and the File Name Pattern contains a token for the current year. If they re-use a file from their PREV submission, the filename will be saved with the current year and not the year when it was originally saved.

Steps to reproduce

Create a webform with a file field and use the submission ID token in the File Name Pattern field.

Set the webform to use autofill from previous submissions.

Create a submission for the webform and see that the filename saves with the current submission ID.

Create another submission for the webform and see that the form autofills. Submit the webform and see that the filename has changed to use the latest submission ID.

View the original webform submission and see that it now uses the latest submission ID in the filename as well.

Proposed resolution

In addFiles method of WebformManagedFileBase, include a check to see if the file already belongs to other webform submissions. If so, do not rename the file with the File Name Pattern.

Perhaps include this as a setting for the file field so that if File Name Pattern is used, site admin can also choose to stop filenames from being changed when autofill is used.

Another idea would be to include a hook during addFiles so that the file can be altered before being saved. This would allow custom modules to make their own changes to the file before saving and accomplish things such as not renaming autofill files without the whole module needing to get a change for what is likely an edge case such as mine.

✨ Feature request
Status

Closed: won't fix

Version

6.2

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada endless_wander

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024