Skip to content

Commit 10fef5a

Browse files
Require user to enter some words
1 parent cd880fe commit 10fef5a

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
</nav>
4242

4343
<div class="jumbotron">
44-
<form class="container">
44+
<form class="container js-form">
4545
<p class="lead">Generate a concise Regular Expression.</p>
4646

4747
<div class="form-group">
4848
<label for="words">
4949
Words or phrases the Regular Expression should match:
5050
</label>
51-
<textarea id="words" class="form-control js-words"></textarea>
51+
<textarea required id="words" class="form-control js-words"></textarea>
5252
</div>
5353

5454
<div class="form-inline">

demo/styles.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
padding-top: 1em;
44
}
55

6+
input:invalid,
7+
textarea:invalid,
8+
select:invalid {
9+
border: 2px solid red;
10+
}
11+
612
#words {
713
height: 15em;
814
}

src/demo.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { parseString, WhitespaceHandling } from './utils/wordList';
44

55
const { Preserve, TrimLeadingAndTrailing } = WhitespaceHandling;
66

7+
const $form = document.querySelector<HTMLFormElement>('.js-form');
78
const $input = document.querySelector<HTMLTextAreaElement>('.js-words');
89
const $delimiter = document.querySelector<HTMLSelectElement>('.js-delimiter');
910
const $caseSensitive = document.querySelector<HTMLInputElement>('.js-case');
@@ -37,6 +38,10 @@ function displayPattern(pattern: string) {
3738
}
3839

3940
function onClickGenerate() {
41+
if (!$form.reportValidity()) {
42+
return;
43+
}
44+
4045
let words = $input.value;
4146
const delimiter = $delimiter.selectedOptions[0].value;
4247
const isCaseSensitive = $caseSensitive.checked;

0 commit comments

Comments
 (0)