Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LiveForm] Files cleared when form error #2625

Open
akyoscommunication opened this issue Mar 4, 2025 · 3 comments · May be fixed by #2628
Open

[LiveForm] Files cleared when form error #2625

akyoscommunication opened this issue Mar 4, 2025 · 3 comments · May be fixed by #2628
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed

Comments

@akyoscommunication
Copy link

When submitting a form with a Live Component (live action), if there is an error, we get a 422 response code because the entity is not valid. That’s expected. However, if the form contains a file input, the live_controller.js script clears the submitted files, preventing the user from reselecting them because they are not in the next requests anymore.

We found these three lines (2123-2125), and when commented out, the issue disappears:

for (const input of Object.values(this.pendingFiles)) { input.value = ''; }

We’re not sure if this is a bug or if it serves another purpose. In any case, resetting the form manually isn't necessary because we already call resetForm() in the Live Action, which clears the files.

@akyoscommunication akyoscommunication added the Bug Bug Fix label Mar 4, 2025
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Mar 4, 2025
@smnandre
Copy link
Member

smnandre commented Mar 5, 2025

I think it mimics here the behaviour of the browser that reset file inputs on submit

@akyoscommunication
Copy link
Author

I understand, but it's not user-friendly to lose the uploaded file if there's an error on the form. There's no other choice when the page refreshes because you can't walk the file through the request and then put it back in the file input after reloading. Here, in the context of a live component with a page that doesn't refresh, we can offer a more practical solution, as long as we don't empty the form. The expected behavior here is : on form submit in a live component, if there is an error on a field when submitting, the component will re-render but the data will remain in the fields, including the files.

We've patched the live_controller.js commenting on these 3 lines and everything seems to be working as expected.

@smnandre
Copy link
Member

smnandre commented Mar 6, 2025

Could you open a PR with these changes, covered by a test or two ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants