Skip to content

Commit 09cfd03

Browse files
docs: update example
1 parent a14d613 commit 09cfd03

File tree

5 files changed

+71
-69
lines changed

5 files changed

+71
-69
lines changed

README.md

+1-34
Original file line numberDiff line numberDiff line change
@@ -1,34 +1 @@
1-
# vue-hooks-form2
2-
3-
## Project setup
4-
```
5-
yarn install
6-
```
7-
8-
### Compiles and hot-reloads for development
9-
```
10-
yarn serve
11-
```
12-
13-
### Compiles and minifies for production
14-
```
15-
yarn build
16-
```
17-
18-
### Run your unit tests
19-
```
20-
yarn test:unit
21-
```
22-
23-
### Run your end-to-end tests
24-
```
25-
yarn test:e2e
26-
```
27-
28-
### Lints and fixes files
29-
```
30-
yarn lint
31-
```
32-
33-
### Customize configuration
34-
See [Configuration Reference](https://cli.vuejs.org/config/).
1+
# Vue Hooks Form

example/App.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<template>
2-
<div id="app">
3-
<Demo />
4-
</div>
2+
<Demo />
53
</template>
64

75
<script lang="ts">

example/components/Demo.vue

+67-30
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
11
<template>
2-
<Input
3-
label="Username"
4-
icon="fa-user"
5-
v-model="username.value"
6-
:ref="username.ref"
7-
:is-danger="!!username.error"
8-
:error-message="username.error && username.error.message"
9-
/>
10-
<Input
11-
label="Password"
12-
type="password"
13-
icon="fa-key"
14-
v-model="password.value"
15-
:ref="password.ref"
16-
:is-danger="!!password.error"
17-
:error-message="password.error && password.error.message"
18-
/>
19-
<Input
20-
label="Confirm Password"
21-
type="password"
22-
icon="fa-key"
23-
v-model="confirmedPassword.value"
24-
:ref="confirmedPassword.ref"
25-
:is-danger="!!confirmedPassword.error"
26-
:error-message="confirmedPassword.error && confirmedPassword.error.message"
27-
/>
28-
<button class="button is-link" @click="onSubmit">Submit</button>
2+
<h1 class="title is-1 container">Vue Hooks Form</h1>
3+
<div class="tile columns">
4+
<div class="column tile ">
5+
<div class="tile is-child box">
6+
<h2 class="title">Example:</h2>
7+
<Input
8+
label="Username"
9+
icon="fa-user"
10+
v-model="username.value"
11+
:ref="username.ref"
12+
:is-danger="!!username.error"
13+
:error-message="username.error && username.error.message"
14+
/>
15+
<Input
16+
label="Password"
17+
type="password"
18+
icon="fa-key"
19+
v-model="password.value"
20+
:ref="password.ref"
21+
:is-danger="!!password.error"
22+
:error-message="password.error && password.error.message"
23+
/>
24+
<Input
25+
label="Confirm Password"
26+
type="password"
27+
icon="fa-key"
28+
v-model="confirmedPassword.value"
29+
:ref="confirmedPassword.ref"
30+
:is-danger="!!confirmedPassword.error"
31+
:error-message="
32+
confirmedPassword.error && confirmedPassword.error.message
33+
"
34+
/>
35+
<button class="button is-link" @click="onSubmit">Submit</button>
36+
</div>
37+
</div>
38+
<div class="column tile">
39+
<div class="tile is-child box">
40+
<h2 class="title">Values:</h2>
41+
<pre>{{ JSON.stringify(values, null, 2) }}</pre>
42+
</div>
43+
</div>
44+
<div class="column tile">
45+
<div class="tile is-child box">
46+
<h2 class="title">ErrorFields:</h2>
47+
<pre>{{ JSON.stringify(errorFields, null, 2) }}</pre>
48+
</div>
49+
</div>
50+
</div>
2951
</template>
3052

3153
<script lang="ts">
@@ -43,7 +65,11 @@ export default defineComponent({
4365
},
4466
setup() {
4567
const {
46-
useField, validateFields, errorFields, getFieldValues, values,
68+
useField,
69+
validateFields,
70+
errorFields,
71+
getFieldValues,
72+
values,
4773
} = useForm({
4874
defaultValues: {
4975
username: 'Victor',
@@ -54,15 +80,19 @@ export default defineComponent({
5480
})
5581
const password = useField('password', {
5682
rule: {
57-
required: true, min: 6, max: 10,
83+
required: true,
84+
min: 6,
85+
max: 10,
5886
},
5987
})
6088
const confirmedPassword = useField('confirmedPassword', {
6189
rule: {
6290
required: true,
6391
validator(rule, value) {
6492
if (!value || value !== (values as any).password) {
65-
return new Error('The two passwords that you entered do not match!')
93+
return new Error(
94+
'The two passwords that you entered do not match!',
95+
)
6696
}
6797
return true
6898
},
@@ -81,7 +111,14 @@ export default defineComponent({
81111
}
82112
},
83113
errorFields,
114+
values,
84115
}
85116
},
86117
})
87118
</script>
119+
120+
<style scoped>
121+
h1 {
122+
text-align: center;
123+
}
124+
</style>

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "vue-hooks-form2",
2+
"name": "vue-hooks-form",
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<noscript>
1313
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
1414
</noscript>
15-
<div id="app"></div>
15+
<div id="app" class="section"></div>
1616
<!-- built files will be auto injected -->
1717
<script defer src="https://use.fontawesome.com/releases/v5.14.0/js/all.js"></script>
1818
</body>

0 commit comments

Comments
 (0)