Skip to content

Commit b06e39d

Browse files
committed
Improve form validation & styling
1 parent 25afa20 commit b06e39d

File tree

2 files changed

+49
-16
lines changed

2 files changed

+49
-16
lines changed

index.html

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
55

66
<title>CodeBedder - simplest code editor on the web</title>
7-
<meta name="description" content="An HTML web component that makes it easy to add code editing to any website" />
8-
<meta name="og:title" content="CodeBedder - simplest code editor on the web" />
9-
<meta name="og:description" content="An HTML web component that makes it easy to add code editing to any website" />
7+
<meta
8+
name="description"
9+
content="An HTML web component that makes it easy to add code editing to any website"
10+
/>
11+
<meta
12+
name="og:title"
13+
content="CodeBedder - simplest code editor on the web"
14+
/>
15+
<meta
16+
name="og:description"
17+
content="An HTML web component that makes it easy to add code editing to any website"
18+
/>
1019
<meta name="og:image" content="screenshot.png" />
1120

1221
<link rel="icon" type="image/svg+xml" href="logo.svg" />
@@ -44,7 +53,10 @@
4453
👀 Try
4554
</a>
4655

47-
<a href="#why" data-title="Why you might want to use it, and why not">
56+
<a
57+
href="#why"
58+
data-title="Why you might want to use CodeBedder (or not)"
59+
>
4860
🤔 Why
4961
</a>
5062

@@ -154,7 +166,7 @@ <h2 id="buy">Need more guidance?</h2>
154166
</div>
155167

156168
<div style="flex: 3">
157-
<dt>🏠 Plus</dt>
169+
<dt>🌷 Plus</dt>
158170
<dd data-price="$500">
159171
We'll help you set up a CodeBedder editor for
160172
<b>any language</b> with a <b>custom preview</b> in up to
@@ -171,10 +183,10 @@ <h2 id="buy">Need more guidance?</h2>
171183
</div>
172184

173185
<div style="flex: 2">
174-
<dt>🏢 Enterprise</dt>
186+
<dt>✨ Xtra</dt>
175187
<dd data-price="$???">
176-
Got <b>many pages</b>? Need a <b>more advanced</b> preview
177-
functionality?
188+
Got <b>many pages</b> in need of a code editor? Need a
189+
<b>more advanced</b> preview functionality?
178190

179191
<p>Or some <b>custom feature</b> you're missing from CodeBedder?</p>
180192

@@ -194,14 +206,15 @@ <h2 id="buy">Need more guidance?</h2>
194206
<dialog
195207
onclick="if (event.target === this) this.close()"
196208
onclose="
197-
if (this.returnValue === 'save') {
198-
// TODO: Error handling
209+
if (this.returnValue === 'submit') {
210+
this.returnValue = '';
199211
fetch('/', {
200212
method: 'POST',
201213
body: new URLSearchParams(new FormData(document.forms.contact)).toString(),
202214
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
215+
}).catch((error) => {
216+
window.alert(error.toString());
203217
});
204-
this.returnValue = '';
205218
}
206219
"
207220
>
@@ -214,11 +227,13 @@ <h2 id="buy">Need more guidance?</h2>
214227
×
215228
</button>
216229

230+
<!-- TODO: Remove if email works without it -->
217231
<input type="hidden" name="form-name" value="contact" />
218-
<input type="email" name="email" placeholder="Email" />
232+
<input type="email" name="email" placeholder="Email" required />
219233
<textarea
220234
name="text"
221235
placeholder="Tell us more about your use case"
236+
required
222237
></textarea>
223238

224239
<div class="toolbar">
@@ -230,7 +245,19 @@ <h2 id="buy">Need more guidance?</h2>
230245
Cancel
231246
</button>
232247

233-
<button type="submit" value="save">Save</button>
248+
<button
249+
type="submit"
250+
value="submit"
251+
onclick="
252+
if (!document.forms.contact.checkValidity()) {
253+
['email', 'text'].forEach((name) => {
254+
document.forms.contact[name].setAttribute('data-dirty', true)
255+
});
256+
}
257+
"
258+
>
259+
Send
260+
</button>
234261
</div>
235262
</form>
236263
</dialog>

style.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ section:has(#buy) button[aria-title='contact us'] {
283283
border-radius: 0.5rem;
284284
border: var(--border);
285285
width: 100%;
286-
padding: 1rem 0.75rem;
286+
padding: 0.75rem;
287287
background-color: var(--primary-500);
288288
color: var(--primary-0);
289289
font-family: var(--font-family-title);
@@ -360,7 +360,7 @@ dialog input,
360360
dialog textarea {
361361
border-radius: 0.5rem;
362362
border: var(--border);
363-
padding: 1rem 0.75rem;
363+
padding: 0.75rem;
364364
}
365365
366366
dialog textarea {
@@ -386,11 +386,16 @@ dialog .toolbar button[value='cancel'] {
386386
color: var(--primary-500);
387387
}
388388
389-
dialog .toolbar button[value='save'] {
389+
dialog .toolbar button[value='submit'] {
390390
background: var(--primary-500);
391391
color: var(--primary-0);
392392
}
393393

394+
input[data-dirty]:invalid,
395+
textarea[data-dirty]:invalid {
396+
border-color: red;
397+
}
398+
394399
/* Footer */
395400
footer,
396401
footer a {
@@ -450,6 +455,7 @@ input,
450455
textarea {
451456
width: 100%;
452457
font-family: var(--font-family-text);
458+
font-size: 1.2rem;
453459
}
454460

455461
textarea {

0 commit comments

Comments
 (0)