Skip to content

Commit f9a9584

Browse files
authored
feat: introduce defineField and deprecate bind API (#4497)
1 parent 43561e2 commit f9a9584

File tree

55 files changed

+630
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+630
-698
lines changed

.changeset/eight-adults-kiss.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vee-validate': patch
3+
---
4+
5+
feat: add label support to defineField closes #4530

docs/src/components/examples/CompositionBasic.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const schema = yup.object({
77
password: yup.string().min(6).required(),
88
});
99
10-
const { defineInputBinds, errors, handleSubmit } = useForm({
10+
const { defineField, errors, handleSubmit } = useForm({
1111
validationSchema: schema,
1212
});
1313
14-
const email = defineInputBinds('email');
15-
const password = defineInputBinds('password');
14+
const [email, emailAttrs] = defineField('email');
15+
const [password, passwordAttrs] = defineField('password');
1616
1717
const onSubmit = handleSubmit(values => {
1818
alert(JSON.stringify(values, null, 2));
@@ -21,10 +21,10 @@ const onSubmit = handleSubmit(values => {
2121

2222
<template>
2323
<form @submit="onSubmit">
24-
<input v-bind="email" name="email" type="email" />
24+
<input v-model="email" v-bind="emailAttrs" name="email" type="email" />
2525
<span>{{ errors.email }}</span>
2626

27-
<input v-bind="password" name="password" type="password" />
27+
<input v-model="password" v-bind="passwordAttrs" name="password" type="password" />
2828
<span>{{ errors.password }}</span>
2929

3030
<button>Submit</button>

docs/src/components/examples/CompositionComponentBindsBasic01.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import { useForm } from 'vee-validate';
33
import CustomInput from './CustomInput.vue';
44
5-
const { values, defineComponentBinds } = useForm();
5+
const { values, defineField } = useForm();
66
7-
const email = defineComponentBinds('email');
7+
const [email, emailProps] = defineField('email');
88
</script>
99

1010
<template>
11-
<CustomInput v-bind="email" />
11+
<CustomInput v-model="email" v-bind="emailProps" />
1212

1313
<pre>values: {{ values }}</pre>
1414
</template>

docs/src/components/examples/CompositionComponentBindsBasic02.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { useForm } from 'vee-validate';
33
import * as yup from 'yup';
44
import CustomInput from './CustomInput.vue';
55
6-
const { values, errors, defineComponentBinds } = useForm({
6+
const { values, errors, defineField } = useForm({
77
validationSchema: yup.object({
88
email: yup.string().email().required(),
99
}),
1010
});
1111
12-
const email = defineComponentBinds('email');
12+
const [email, emailProps] = defineField('email');
1313
</script>
1414

1515
<template>
16-
<CustomInput v-bind="email" />
16+
<CustomInput v-model="email" v-bind="emailProps" />
1717

1818
<pre>errors: {{ errors }}</pre>
1919
<pre>values: {{ values }}</pre>

docs/src/components/examples/CompositionComponentBindsBasic03.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import { useForm } from 'vee-validate';
33
import * as yup from 'yup';
44
import CustomInput from './CustomInput.vue';
55
6-
const { values, errors, defineComponentBinds } = useForm({
6+
const { values, errors, defineField } = useForm({
77
validationSchema: yup.object({
88
email: yup.string().email().required(),
99
}),
1010
});
1111
12-
const email = defineComponentBinds('email', {
12+
const [email, emailProps] = defineField('email', {
1313
validateOnValueUpdate: false,
1414
});
1515
</script>
1616

1717
<template>
18-
<CustomInput v-bind="email" />
18+
<CustomInput v-model="email" v-bind="emailProps" />
1919
<div>{{ errors.email }}</div>
2020

2121
<pre>values: {{ values }}</pre>

docs/src/components/examples/CompositionComponentBindsBasic04.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { useForm } from 'vee-validate';
33
import * as yup from 'yup';
44
import CustomInput from './CustomInput.vue';
55
6-
const { values, errors, defineComponentBinds } = useForm({
6+
const { values, errors, defineField } = useForm({
77
validationSchema: yup.object({
88
email: yup.string().email().required(),
99
}),
1010
});
1111
12-
const email = defineComponentBinds('email', {
13-
mapProps: state => ({
12+
const [email, emailProps] = defineField('email', {
13+
props: state => ({
1414
error: state.errors[0],
1515
}),
1616
});
1717
</script>
1818

1919
<template>
20-
<CustomInput v-bind="email" />
20+
<CustomInput v-model="email" v-bind="emailProps" />
2121

2222
<pre>values: {{ values }}</pre>
2323
<pre>errors: {{ errors }}</pre>
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,24 @@
11
<script setup>
22
import { useForm } from 'vee-validate';
33
import * as yup from 'yup';
4-
import CustomInput from './CustomInput.vue';
54
6-
const { values, errors, defineInputBinds, defineComponentBinds } = useForm({
5+
const { values, errors, defineField } = useForm({
76
validationSchema: yup.object({
87
email: yup.string().email().required(),
9-
emailComponent: yup.string().email().required(),
108
}),
119
});
1210
13-
const email = defineInputBinds('email', state => {
14-
return {
15-
// validate aggressively as long as there are errors on the input
16-
validateOnInput: state.errors.length > 0,
17-
};
18-
});
19-
20-
const emailComponent = defineComponentBinds('emailComponent', state => {
11+
const [email, emailAttrs] = defineField('email', state => {
2112
return {
2213
// validate aggressively as long as there are errors on the input
2314
validateOnModelUpdate: state.errors.length > 0,
24-
validateOnBlur: true,
25-
props: {
26-
error: state.errors[0],
27-
},
2815
};
2916
});
3017
</script>
3118

3219
<template>
33-
<input v-bind="email" />
20+
<input v-model="email" v-bind="emailAttrs" />
3421
<div>{{ errors.email }}</div>
3522

36-
<CustomInput v-bind="emailComponent" />
37-
3823
<pre>values: {{ values }}</pre>
3924
</template>

docs/src/components/examples/CompositionComponentBindsBasic06.vue

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/src/components/examples/CompositionDynamicSchemaComputed.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ import * as yup from 'yup';
66
77
const limit = ref(5);
88
9-
const { errors, defineInputBinds } = useForm({
9+
const { errors, defineField } = useForm({
1010
validationSchema: computed(() =>
1111
toTypedSchema(
1212
yup.object({
1313
content: yup.string().max(limit.value),
14-
})
15-
)
14+
}),
15+
),
1616
),
1717
});
1818
19-
const content = defineInputBinds('content');
19+
const [content, contentAttrs] = defineField('content');
2020
</script>
2121

2222
<template>
2323
<input v-model.number="limit" />
2424

25-
<input v-bind="content" />
25+
<input v-model="content" v-bind="contentAttrs" />
2626
<div>{{ errors.content }}</div>
2727
</template>

docs/src/components/examples/CompositionDynamicSchemaYupLazy.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ import * as yup from 'yup';
66
77
const limit = ref(5);
88
9-
const { errors, defineInputBinds } = useForm({
9+
const { errors, defineField } = useForm({
1010
validationSchema: toTypedSchema(
1111
yup.lazy(() =>
1212
yup.object({
1313
content: yup.string().max(limit.value),
14-
})
15-
)
14+
}),
15+
),
1616
),
1717
});
1818
19-
const content = defineInputBinds('content');
19+
const [content, contentAttrs] = defineField('content');
2020
</script>
2121

2222
<template>
2323
<input v-model.number="limit" />
2424

25-
<input v-bind="content" />
25+
<input v-model="content" v-bind="contentAttrs" />
2626
<div>{{ errors.content }}</div>
2727
</template>

0 commit comments

Comments
 (0)