aboutsummaryrefslogtreecommitdiff
path: root/src/routes/+page.svelte
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-01 15:15:37 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-01 15:15:37 +0200
commitb30150a8feb960c0667eaff6cb105dcc55b65744 (patch)
treeb953226c6dc323b2b83c2df9677460c4aa4697e6 /src/routes/+page.svelte
parent59c840c21798d515bfc375bead87e690cd70900a (diff)
fix(groceries): prevent premature auto-submit on quick-add input
Typing 'sel régénérant' would auto-submit 'sel' because oninput fired on every keystroke, and trim() collapsed the partial input to a catalog match. Moved auto-submit to oninput with insertReplacementText guard (datalist selection) plus onchange (blur/Enter), so regular typing is never interrupted.
Diffstat (limited to 'src/routes/+page.svelte')
-rw-r--r--src/routes/+page.svelte12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 6611bbc..9900bb3 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -94,6 +94,18 @@
}
}}
oninput={(e) => {
+ if ((e as InputEvent).inputType === 'insertReplacementText') {
+ const val = e.currentTarget.value.trim().toLowerCase();
+ const match = data.catalog.find(
+ (item) => item.name.toLowerCase() === val,
+ );
+ if (match) {
+ name = match.name;
+ handleAdd(false);
+ }
+ }
+ }}
+ onchange={(e) => {
const val = e.currentTarget.value.trim().toLowerCase();
const match = data.catalog.find(
(item) => item.name.toLowerCase() === val,