Skip to content

Commit e034433

Browse files
committed
Added aria-invalid to errorSelector option.
1 parent 53dd771 commit e034433

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Multiple `regex` and `step` is now allowed in a schema. A warning will be emitted by default, that can be turned off.
1717
- The signature for `options.resetForm` has changed to `boolean | () => boolean` (it was async before).
1818
- The undocumented `defaultData` is now called `defaultValues`.
19+
- Added `[aria-invalid="true"]` to `errorSelector` option.
1920

2021
### Removed
2122

src/lib/client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const defaultFormOptions = {
154154
resetForm: false,
155155
autoFocusOnError: 'detect',
156156
scrollToError: 'smooth',
157-
errorSelector: '[data-invalid]',
157+
errorSelector: '[data-invalid],[aria-invalid="true"]',
158158
selectErrorText: false,
159159
stickyNavbar: undefined,
160160
taintedMessage:

src/routes/valid/+page.svelte

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
77
export let data: PageData;
88
9-
const { form, errors, enhance, delayed, message, valid } = superForm(
10-
data.form,
11-
{
9+
const { form, errors, enhance, delayed, message, valid, constraints } =
10+
superForm(data.form, {
1211
validators: $page.url.searchParams.has('zod')
1312
? userSchema.extend({
1413
id: userSchema.shape.id.optional()
@@ -19,8 +18,7 @@
1918
email: (email: string) =>
2019
!email.includes('@') ? 'Enter a valid email address' : null
2120
}
22-
}
23-
);
21+
});
2422
</script>
2523

2624
<a href="/">&lt; Back to start</a>
@@ -51,18 +49,17 @@
5149

5250
<label>
5351
Name<br />
54-
<input name="name" data-invalid={$errors.name} bind:value={$form.name} />
52+
<input
53+
name="name"
54+
aria-invalid={$errors.name ? 'true' : undefined}
55+
bind:value={$form.name}
56+
/>
5557
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if}
5658
</label>
5759

5860
<label>
5961
E-mail<br />
60-
<input
61-
name="email"
62-
type="email"
63-
data-invalid={$errors.email}
64-
bind:value={$form.email}
65-
/>
62+
<input name="email" type="email" bind:value={$form.email} />
6663
{#if $errors.email}<span class="invalid">{$errors.email}</span>{/if}
6764
</label>
6865

0 commit comments

Comments
 (0)