This repository was archived by the owner on Apr 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.vue
98 lines (85 loc) · 1.59 KB
/
App.vue
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<template>
<h2>Playground</h2>
<form @submit.prevent="submitForm">
<input
v-bind="
register('playground', {
validate: {
syncValidation: (value: string) =>
value?.length > 0 || 'Value cannot be empty',
},
})
"
/>
<button>Submit</button>
<pre>{{ formState }}</pre>
</form>
</template>
<script setup lang="ts">
import { useFormHandler } from '../src/index'
const { register, handleSubmit, formState, build } = useFormHandler()
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
const testValidation = async (value: string) => {
await sleep(3000)
if (value === 'test') {
return 'Value cannot be "test"'
}
return true
}
const submitForm = () => {
handleSubmit((form: any) => {
console.log(form)
})
}
const form = build({
playground: {},
})
</script>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
text-align: center;
}
body {
display: flex;
align-items: center;
justify-content: center;
background-color: #242424;
font-family: 'Open Sans', sans-serif;
font-size: 16px;
color: #42b883;
min-height: 100vh;
}
h2 {
margin: 1em;
}
label {
display: block;
}
form {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 1em;
}
input,
select,
textarea,
button {
border: none;
border-radius: 5px;
width: 300px;
min-height: 40px;
background-color: #35495e;
color: #42b883;
}
button {
background-color: #42b883;
color: #35495e;
cursor: pointer;
text-transform: uppercase;
font-weight: bold;
}
</style>