@samuel-charpentier/sform 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,6 +6,7 @@
6
6
  TypedSfieldProps
7
7
  } from './types.js';
8
8
  import { getSformContext } from './context.svelte.js';
9
+ import { tick } from 'svelte';
9
10
  import TextInput from './inputs/TextInput.svelte';
10
11
  import NumberInput from './inputs/NumberInput.svelte';
11
12
  import TextareaInput from './inputs/TextareaInput.svelte';
@@ -56,8 +57,15 @@
56
57
  const issues = $derived(showIssues ? field.issues() : []);
57
58
  const hasIssues = $derived(issues && issues instanceof Array && issues.length > 0);
58
59
 
59
- function handleBlur() {
60
+ async function handleBlur() {
60
61
  context.markTouched(name);
62
+ // Wait a tick - if submission started, pending will be > 0 by then
63
+ // This prevents stale data validation when blur fires during Enter submission
64
+ await tick();
65
+ const formState = context.getFormState();
66
+ if (formState.pending) {
67
+ return;
68
+ }
61
69
  // Trigger validation with includeUntouched so blur mode shows issues
62
70
  context.triggerValidation();
63
71
  }
@@ -57,10 +57,7 @@
57
57
  () => validateOn,
58
58
  getFieldNames,
59
59
  triggerValidation,
60
- () => {
61
- // Use setTimeout to ensure we're outside the current event loop
62
- setTimeout(() => formElement?.requestSubmit(), 0);
63
- },
60
+ () => formElement?.requestSubmit(),
64
61
  () => form
65
62
  );
66
63
 
@@ -89,7 +86,6 @@
89
86
  });
90
87
 
91
88
  function handleInput() {
92
- // Always include untouched to preserve issues on fields that were already validated
93
89
  form.validate({ includeUntouched: true });
94
90
  }
95
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samuel-charpentier/sform",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "A Svelte 5 form library for SvelteKit remote forms",
5
5
  "keywords": [
6
6
  "svelte",