forked from denoland/deploy_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.jsx
44 lines (42 loc) · 1.11 KB
/
search.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { h } from "https://deno.land/x/[email protected]/mod.ts";
/** Validate if the form value follows the appropriate
* structure (<owner>/<repo>). */
function validateForm() {
// deno-lint-ignore no-undef
const repository = document.forms["search"]["repository"].value;
if (repository.split("/").length !== 2) {
alert(
`Input should be in the form of 'owner/repository'. No forward slashes at the beginning or end.`,
);
return false;
}
return true;
}
export default function Search() {
return (
<div>
<script dangerouslySetInnerHTML={{ __html: validateForm }} />
<form
className="flex items-center mt-8"
name="search"
action="/"
method="get"
onSubmit="return validateForm()"
>
<input
className="rounded border px-4 h-8 mr-2"
type="search"
name="repository"
placeholder="<owner>/<repo>"
required
/>
<button
className="bg-blue-600 text-white px-2 rounded h-8"
type="submit"
>
Search
</button>
</form>
</div>
);
}