You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b018a22
Browse filesBrowse the repository at this point in the historyBrowse files
feat(pages): add useForm setError and clear field errors on change
Fixes#525
## Summary
Adds `setError(field, message)` to `useForm` across React, Vue, Svelte, and Solid so apps can surface client-side validation through the same typed `errors` object as server `withValidator()` responses. Changing a field clears that field's validation error automatically (`setData` / `data` assignment).
## Changes
- Add public `setError(field, message)` on `useForm` for all four frameworks.
- Clear `errors[field]` on field change via `setData` (React/Solid) or `data` assignment (Vue/Svelte).
- Update docs for actions/forms and the pages API reference.
- Add Vue unit coverage for `setError` and clear-on-change.
## Testing
- `packages/vue/test/unit/use-form.test.ts`
- Typecheck `@void/react`, `@void/vue`, `@void/svelte`, `@void/solid`
Co-authored-by: froQ <sayhola@froq.me>
Copy file name to clipboardExpand all lines: docs/guide/pages-routing/actions-and-forms.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,9 +159,12 @@ The types are inferred from your action's `withValidator()` schema in the compan
159
159
|`recentlySuccessful`|`true` for 2 seconds after a successful submission. Useful for flash messages. |
160
160
|`reset(...fields)`| Reset form data to the current defaults (last submitted values after success). Field names autocomplete. Pass `{ initial: true }` first to reset to the values passed to `useForm`. |
161
161
|`resetOnSuccess` (option) | When `true`, a successful submit resets both form data and defaults to the mount-time values. Useful for create forms that should clear after save. |
162
+
|`setError(field, message)`| Set a client-side validation error on a field. |
162
163
|`clearErrors(...fields)`| Clear validation errors. Field names autocomplete. |
163
164
|`clearError()`| Clear `error`. |
164
165
166
+
Changing a field clears that field's validation error automatically (`setData` in React and Solid, or assigning to `data` in Vue and Svelte).
167
+
165
168
For a native React form, use `form.post`, `form.put`, `form.patch`, or `form.delete` as a native form action. For an awaitable mutation, use `action()`. In Vue, Svelte, and Solid, form submissions return `Promise<void>`; catch thrown errors or use your framework's error handling.
Copy file name to clipboardExpand all lines: docs/reference/api/pages.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ Imported from `"@void/vue"`.
49
49
|`useRouter()`| Returns the Void Router with current route state (`url`, `path`, `query`, `params`) and navigation methods: `visit`, `refresh`, awaitable `prefetch`, `flush`, `flushAll`. |
50
50
|`useParams()`| Returns dynamic route params for the page currently being rendered. |
51
51
|`useNavigation()`| Returns pending navigation state: `{ state, location, method }`, where `state` is `"idle"`, `"loading"`, or `"submitting"` and `location` is the pending destination. |
52
-
|`useForm(url, defaults, options?)`| Typed reactive form helper bound to a page action URL. Returns `{ data, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, clearErrors, clearError }`.|
52
+
|`useForm(url, defaults, options?)`| Typed reactive form helper bound to a page action URL. Returns `{ data, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, setError, clearErrors, clearError }`. |
53
53
|`useIslandForm(defaults)`| Form helper for island components. Same form state as `useForm()`, plus `submit(url, method)`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. |
54
54
|`action(url, options?)`| Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an `ActionResult`. |
55
55
|`useShared()`| Returns shared data injected by middleware via `c.set("shared", {...})`. |
@@ -101,7 +101,7 @@ Imported from `"@void/react"`.
101
101
|`useRouter()`| Returns the Void Router with current route state (`url`, `path`, `query`, `params`) and navigation methods: `visit`, `refresh`, awaitable `prefetch`, `flush`, `flushAll`. React navigations are scheduled as transitions. |
102
102
|`useParams()`| Returns dynamic route params for the page currently being rendered. |
103
103
|`useNavigation()`| Returns pending navigation state: `{ state, location, method }`, where `state` is `"idle"`, `"loading"`, or `"submitting"` and `location` is the pending destination. |
|`useIslandForm(defaults)`| Form helper hook for island components. Same form state as `useForm()`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. |
106
106
|`action(url, options?)`| Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an `ActionResult`. |
107
107
|`useShared()`| Returns shared data injected by middleware via `c.set("shared", {...})`. |
@@ -158,7 +158,7 @@ Imported from `"@void/svelte"`.
|`Link`| Svelte component for SPA navigation. Renders `<a>` for GET, `<button>` for non-GET methods. Props: `href`, `method`, `data`, `prefetch`, `cacheFor`, `preserveScroll`, `preserveState`, `replace`, `reloadDocument`, `viewTransition`, `onNavigate`. |
161
-
|`useForm(url, defaults, options?)`| Form helper using Svelte 5 runes. Returns `{ data, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, clearErrors, clearError }`.|
161
+
|`useForm(url, defaults, options?)`| Form helper using Svelte 5 runes. Returns `{ data, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, setError, clearErrors, clearError }`. |
162
162
|`useIslandForm(defaults)`| Form helper for island components. Same form state as `useForm()`, plus `submit(url, method)`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. |
163
163
|`action(url, options?)`| Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an `ActionResult`. |
164
164
|`useShared()`| Returns shared data injected by middleware via `c.set("shared", {...})`. |
@@ -208,7 +208,7 @@ Imported from `"@void/solid"`.
|`Link`| Solid component for SPA navigation. Renders `<a>` for GET, `<button>` for non-GET methods. Props: `href`, `method`, `data`, `prefetch`, `cacheFor`, `preserveScroll`, `preserveState`, `replace`, `reloadDocument`, `viewTransition`, `onNavigate`. |
211
-
|`useForm(url, defaults, options?)`| Form helper using Solid stores. Returns `{ data, setData, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, clearErrors, clearError }`.|
211
+
|`useForm(url, defaults, options?)`| Form helper using Solid stores. Returns `{ data, setData, post, put, patch, delete, pending, errors, error, hasChanges, wasSuccessful, recentlySuccessful, reset, setError, clearErrors, clearError }`. |
212
212
|`useIslandForm(defaults)`| Form helper for island components. Same form state as `useForm()`. `post(url)`, `put(url)`, `patch(url)`, and `delete(url)` take the action URL and submit with `fetch()`. |
213
213
|`action(url, options?)`| Awaitable one-shot page action helper. Uses `POST` by default and accepts `{ data, method, params }`, where `method` can be `"PUT"`, `"PATCH"`, or `"DELETE"`. Returns an `ActionResult`. |
214
214
|`useShared()`| Returns shared data injected by middleware via `c.set("shared", {...})`. |
0 commit comments