fix: validate input on submit

This commit is contained in:
Ondřej Synáček 2020-12-25 10:15:28 +01:00
parent 2d195fd48c
commit 37d931f6ce
1 changed files with 6 additions and 1 deletions

View File

@ -28,6 +28,7 @@
export let pending
let value
let form
const onChange = (e) => {
value = e.currentTarget.value
@ -41,12 +42,16 @@
console.log(inputClasses)
const handleSubmit = async (e) => {
if (!form.reportValidity()) {
return
}
e.preventDefault()
createEvent(value, { logger })
}
</script>
<form id="form">
<form id="form" bind:this={form}>
<input
required
pattern="^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|\d+$"