Skip to content

Commit a5b0004

Browse files
authored
docs: focus added input on form example (#787)
1 parent 69a50d3 commit a5b0004

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

apps/www/src/routes/examples/forms/profile-form.svelte

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import { zodClient } from "sveltekit-superforms/adapters";
2626
import { cn } from "$lib/utils";
2727
import { browser } from "$app/environment";
28+
import { tick } from "svelte";
2829
2930
export let data: SuperValidated<Infer<ProfileFormSchema>>;
3031
@@ -36,6 +37,14 @@
3637
3738
function addUrl() {
3839
$formData.urls = [...$formData.urls, ""];
40+
41+
tick().then(() => {
42+
const urlInputs = Array.from(
43+
document.querySelectorAll<HTMLElement>("#profile-form input[name='urls']")
44+
);
45+
const lastInput = urlInputs[urlInputs.length - 1];
46+
lastInput && lastInput.focus();
47+
});
3948
}
4049
4150
$: selectedEmail = {
@@ -44,7 +53,7 @@
4453
};
4554
</script>
4655

47-
<form method="POST" class="space-y-8" use:enhance>
56+
<form method="POST" class="space-y-8" use:enhance id="profile-form">
4857
<Form.Field {form} name="username">
4958
<Form.Control let:attrs>
5059
<Form.Label>Username</Form.Label>

0 commit comments

Comments
 (0)