update: point fix at correct place.

This commit is contained in:
ItzNotABug committed 2024-08-30 16:52:18 +05:30
1 parent 63f2e421b4
commit 8e9dc9f6f8
2 files changed
+2 -38

No files matched your search

+2 -27
View File
@@ -54,41 +54,16 @@
}
}
async function focusDigitInputs() {
/**
* this is to re-focus the inputs that feels natural
* as the blinking of the cursor takes around 250ms.
*/
await sleep(250);
onMount(() => {
const interval = setInterval(() => {
const input = element.querySelector('input');
if (element) {
/**
* Ensure the value is empty before refocusing.
*
* If the value is not cleared and the form is submitted,
* the cursor will move to the first field while the last field remains filled.
* This would cause the focus to appear visually odd and very inconsistent.
*/
if (input && autofocus && value === '') {
if (input && autofocus) {
input.focus();
}
clearInterval(interval);
}
}, 10);
}
onMount(() => {
/**
* Inputs will lose focus on any change.
* Changes include the url & query params like `?redirect=`.
*
* This subscription ensures that focus is restored when needed.
*/
return page.subscribe(() => {
focusDigitInputs();
});
});
</script>
@@ -51,17 +51,6 @@
await goto(`${base}/apply-credit?campaign=${data.campaign}`);
return;
}
if ($page.url.searchParams) {
const redirect = $page.url.searchParams.get('redirect');
$page.url.searchParams.delete('redirect');
if (redirect) {
await goto(`${redirect}${$page.url.search}`);
} else {
await goto(`${base}${$page.url.search ?? ''}`);
}
} else {
await goto(base);
}
} catch (error) {
disabled = false;
addNotification({