-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
data-sveltekit-keepfocus
does not work on POST forms
#10796
Comments
I'll admit I've never used this option and was confused by the documentation. However, at the top of the page it does mention:
This could be made a bit clearer that it only works on GET form submissions? or is there a good case for keeping focus for POST form submissions? (seems we always reset even with use:enhance with no way to opt out) |
@s3812497 - that would make sense. I totally missed it.
Sure there is. You don't really have to have a 'submit' button on input fields for some cases (like 'a note for the item'). So I want to save some data by POST but allow the user to keep focus while editing it. For accessibility you just display the buttons in Or currently I'm using the same thing on following profile edit form in tall.ly - you edit the inputs, but the form is submitted automatically and an status icon is displayed on save |
data-sveltekit-keepfocus
does not workdata-sveltekit-keepfocus
does not work on POST forms
I would also need this for a POST form using autosave. Whats your current workaround @z-x? |
@rikardkling - https://twitter.com/z_x/status/1731347776280092873 You can temporarily set
|
Hello, I hope this message finds you well. Please excuse any unintended rudeness as I am using a translation tool for communication. I am reaching out to suggest the possibility of extending support for POST requests in addition to the existing functionality. The goal in my case is to achieve consistent results in both active and inactive states of JavaScript. The use:enhance directive is indeed a fantastic feature. It provides a consistent feeling of developer experience (DX) without cluttering the code, which is highly appreciated. However, to maintain focus without losing it during POST requests, some workaround code becomes necessary. For instance, if we consider liking the fifth feed out of ten using only the keyboard, under the current circumstances, to view the sixth post, it's required to track the last clicked like button of the feed with a state variable that can be provided to autofocus. My question is, despite the anticipation that data-sveltekit-keepfocus would abstract such processes, why does it only support GET requests? Is there a specific reason for this limitation? Thank you for your time and consideration. |
UPDATE: As explained by @s3812497 - I was confused and missed the info in the dosc, that this only works for GET forms, this would be a feature request for POST forms then as well.
There were two tickets related to this: #7895 and #9019 with the actual implementation.
The documentation confirms that we should be able to use
data-sveltekit-keepfocus
on a<form>
element not to loose focus after the form is being submitted.This seem not to work for me. Nor for forms with
use:enhance
, neither for those without. I've created a simple reproduction code: https://stackblitz.com/edit/sveltejs-kit-template-default-du58bc?file=src%2Froutes%2F%2Bpage.svelte Either that, or I don't fully understand how should it work from the docs.Reproduction
use:enhance
data-sveltekit-keepfocus
attribute to iton:input
or use https://stackblitz.com/edit/sveltejs-kit-template-default-du58bc?file=src%2Froutes%2F%2Bpage.svelte
Severity
serious, but I can work around it
The text was updated successfully, but these errors were encountered: