Skip to content

Commit 2d17bd3

Browse files
committed
add unique ids to form labels
1 parent afaa723 commit 2d17bd3

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/js/components/FeedbackFormBasic/index.svelte

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
summaryError = $state(),
1010
descriptionError = $state(false);
1111
12+
const id = $props.id();
13+
const form = `form#${id}`;
14+
1215
//takes long string output of document.cookie and splits it into a usable javascript object
1316
let cookies = document.cookie
1417
.split(';')
@@ -26,8 +29,6 @@
2629
2730
/**
2831
* @typedef {Object} Props
29-
* @property {any} [id]
30-
* @property {any} [form]
3132
* @property {any} postResponseStatusCode
3233
* @property {boolean} [loading] - when true, spinner on submit button animates
3334
* @property {boolean} [hidden] - when true, hides the element (in this case, the form)
@@ -38,8 +39,6 @@
3839
3940
/** @type {Props} */
4041
let {
41-
id = `id${new Date().getTime()}`,
42-
form = `form#${id}`,
4342
postResponseStatusCode = $bindable(),
4443
loading = $bindable(false),
4544
hidden = $bindable(false),
@@ -143,12 +142,14 @@
143142
<main>
144143
<form {onsubmit} class:hidden class="needs-validation mb-3" name="feedback" novalidate {id}>
145144
<div class="mb-3">
146-
<label for="name" class="form-label">Name <span class="required" aria-hidden="true">(required)</span> </label>
145+
<label for="{id}-name" class="form-label"
146+
>Name <span class="required" aria-hidden="true">(required)</span>
147+
</label>
147148
<input
148149
aria-describedby="name-error"
149150
type="name"
150151
class="form-control"
151-
id="name"
152+
id="{id}-name"
152153
name="name"
153154
autocomplete="name"
154155
required
@@ -160,13 +161,13 @@
160161
</div>
161162
</div>
162163
<div class="mb-3">
163-
<label for="email" class="form-label"
164+
<label for="{id}-email" class="form-label"
164165
>Email address <span class="required" aria-hidden="true">(required)</span></label
165166
>
166167
<input
167168
type="email"
168169
class="form-control"
169-
id="email"
170+
id="{id}-email"
170171
name="email"
171172
aria-describedby="email-error"
172173
autocomplete="email"
@@ -177,31 +178,38 @@
177178
</div>
178179
</div>
179180
<div class="mb-3">
180-
<label for="summary" class="form-label"
181+
<label for="{id}-summary" class="form-label"
181182
>Short summary <span class="required" aria-hidden="true">(required)</span></label
182183
>
183-
<input type="text" class="form-control" id="summary" name="summary" aria-describedby="summary-error" required />
184+
<input
185+
type="text"
186+
class="form-control"
187+
id="{id}-summary"
188+
name="summary"
189+
aria-describedby="summary-error"
190+
required
191+
/>
184192
<div class="invalid-feedback" id="summary-error">
185193
{#if summaryError}<span>Error: Please provide a title or subject line to summarize your feedback.</span>{/if}
186194
</div>
187195
</div>
188196
<div class="mb-3">
189-
<label for="bookDescription" class="form-label"
197+
<label for="{id}-bookDescription" class="form-label"
190198
>If your question is related to a specific book, what is the title or URL? <span
191199
class="required"
192200
aria-hidden="true">(optional)</span
193201
></label
194202
>
195-
<input type="text" class="form-control" id="bookDescription" name="bookDescription" />
203+
<input type="text" class="form-control" id="{id}-bookDescription" name="bookDescription" />
196204
</div>
197205
<div class="mb-3">
198-
<label for="description" class="form-label"
206+
<label for="{id}-description" class="form-label"
199207
>Full description of problem or question <span class="required" aria-hidden="true">(required)</span></label
200208
>
201209
<textarea
202210
class="form-control"
203211
aria-describedby="description-error"
204-
id="description"
212+
id="{id}-description"
205213
name="description"
206214
rows="3"
207215
required

0 commit comments

Comments
 (0)