fix: input form validation
This commit is contained in:
parent
579bde6c32
commit
c27b91cd06
|
@ -30,31 +30,27 @@
|
||||||
let value
|
let value
|
||||||
let form
|
let form
|
||||||
|
|
||||||
const onChange = (e) => {
|
|
||||||
value = e.currentTarget.value
|
|
||||||
}
|
|
||||||
|
|
||||||
let inputClasses = ''
|
let inputClasses = ''
|
||||||
$: inputClasses = [
|
$: inputClasses = [
|
||||||
error ? 'input--error' : '',
|
error ? 'input--error' : '',
|
||||||
pending ? 'input--pending': '',
|
pending ? 'input--pending': '',
|
||||||
].join(' ')
|
].join(' ')
|
||||||
console.log(inputClasses)
|
|
||||||
|
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = (e) => {
|
||||||
if (!form.reportValidity()) {
|
if (!form.reportValidity()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
createEvent(value, { logger })
|
createEvent(value, { logger })
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<form id="form" bind:this={form}>
|
<form id="form" on:submit={handleSubmit} bind:this={form}>
|
||||||
<input
|
<input
|
||||||
required
|
required
|
||||||
pattern="^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|\d+$"
|
pattern={String.raw`^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?|\d+$`}
|
||||||
id="url"
|
id="url"
|
||||||
name="url"
|
name="url"
|
||||||
class={inputClasses}
|
class={inputClasses}
|
||||||
|
|
Loading…
Reference in New Issue