-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add reference to hx-preserve to the example at "Preserving File Inputs after Form Errors" #2474
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
Conversation
Your testing is so good, I wonder if maybe it would help to include some of that in the documentation as well? This bit especially:
|
Hey @Matt544 , are you still interested in this change? If so, what do you think of alex's suggestion above? Thanks! |
Greetings @Telroshan , thanks for the nudge. And thanks @alexpetros for the initial feedback. Sorry for going awol there: various poor excuses apply. I agree with Alex's suggestion. I have made changes to my pull request branch to reflect the suggestion. I'm not totally clear on the process for updating a pull request (this is my first time trying to contribute to an open source project). My branch 'pr_branch' contains the changes. Please let me know if I should do anything more. Thanks. |
Hey @Matt544, first of all no worries at all about the delay, look how long it took me to get back to this PR in the first place! Thanks for your first open source contribution then 😄 In these cases you should If you can't manage to rebase and have only your commits in the PR diff (i.e. without bringing along the ~250 other commits), there's always the last resort of closing this PR and opening a new one starting fresh from the latest commit (call it dirty but hey, it works). |
I think I have managed the rebase, thanks for the advice on that. Note: I did "manual" testing of the suggested approach of using Just let me know if I can do anything else to assist. Cheers. |
Thanks! |
…s after Form Errors" (bigskysoftware#2474) * Add reference to hx-preserve to file-upload-input.md * Address review feedback: add more description behaviour when using .
…s after Form Errors" (bigskysoftware#2474) * Add reference to hx-preserve to file-upload-input.md * Address review feedback: add more description behaviour when using .
Description
I have added a second approach to preserving file inputs after form errors (in the example at file-upload-input.md), using
hx-preserve
.The approach currently suggested requires a restructuring of the form that will not always be feasible or convenient. I have found that adding
hx-preserve
to the file inputcauses the expected behavior: the user does not have to choose a file again before
re-submitting the form.
The approach is:
I feel this change is necessary because the current version of file-upload-input.md
leaves the impression that there is no htmx attribute that can preserve the file input's
value if the input is within the area that htmx will swap. I'm a little
embarrassed to say that this is the conclusion I drew when I saw the current version of
file-upload-input.md and I charged ahead and made an extension that moved my input out
of the swap zone and put it back after the swap. My bad. But it might help others to
point out that
hx-preserve
is available for this use case.Testing
My own testing on the
hx-preserve
approach shows it can acheive the following behaviour:if the form has errors and is returned, the original file input choice is preserved
and the form can be successfully re-submitted.
if the file field has errors on it, they will be displayed provided that
hx-preserve
wasplaced in the
input
only and not the errors element (e.g.ol.errorlist
)if you want the file upload input to return without the user's chosen file
because the field was invalid, you can manage that on the server side by omitting
the
hx-preserve
attribute when the field has errors. (For example, if the userchooses an invalid file type, you may want the file field to come back with no
value so the user is forced to make another choice.)
Checklist
master
for website changes,dev
forsource changes)
master
branch. Sorry if that didn't work!approved via an issue
npm run test
) and verified that it succeededwww
.