Skip to content

Commit 9bfbfaa

Browse files
viajes7logaretm
authored andcommitted
feat: add isValidating state while validate method is running (#4244)
1 parent 09d5596 commit 9bfbfaa

File tree

14 files changed

+191
-2
lines changed

14 files changed

+191
-2
lines changed

.changeset/purple-eggs-ring.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: added isValidating to useForm

docs/src/pages/api/composition-helpers.mdx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ useIsSubmitting.value; // true or false
258258

259259
<CodeTitle level="4">
260260

261+
`useIsValidating(): ComputedRef<boolean>`
262+
263+
</CodeTitle>
264+
265+
Returns a computed ref to the form's `isValidating` state.
266+
267+
```js
268+
import { useIsValidating } from 'vee-validate';
269+
270+
const isValidating = useIsValidating();
271+
272+
isValidating.value; // true or false
273+
```
274+
275+
<CodeTitle level="4">
276+
261277
`useSubmitCount(): ComputedRef<number>`
262278

263279
</CodeTitle>

docs/src/pages/api/form.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ Indicates if the submission handler is still running, once it resolves/rejects i
167167

168168
<CodeTitle level="4">
169169

170+
`isValidating: boolean`
171+
172+
</CodeTitle>
173+
174+
Indicates if the validate function is still running, once validate function is done it will be automatically set to `false` again.
175+
176+
<CodeTitle level="4">
177+
170178
`meta: FormMeta`
171179

172180
</CodeTitle>

docs/src/pages/api/use-form.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ type useForm = (opts?: FormOptions) => {
187187
errorBag: ComputedRef<Partial<Record<string, string[]>>>; // all error messages for each field
188188
meta: ComputedRef<FormMeta<TValues>>; // aggregate of the field's meta information
189189
isSubmitting: Ref<boolean>; // if the form submission function is being run
190+
isValidating: Ref<boolean>; // if the form validate function is being run
190191
setFieldValue<T extends keyof TValues>(field: T, value: TValues[T]): void; // Sets a field value
191192
setFieldError: (field: keyof TValues, message: string | string[] | undefined) => void; // Sets an error message for a field
192193
setErrors: (fields: FormErrors<TValues>) => void; // Sets error messages for fields
@@ -332,6 +333,20 @@ isSubmitting.value; // true or false
332333

333334
<CodeTitle level="4">
334335

336+
`isValidating: Ref<boolean>`
337+
338+
</CodeTitle>
339+
340+
Indicates if the validate function is still running, once validate function is done it will be automatically set to `false` again.
341+
342+
```js
343+
const { isValidating } = useForm();
344+
345+
isValidating.value; // true or false
346+
```
347+
348+
<CodeTitle level="4">
349+
335350
`meta: ComputedRef<FormMeta>`
336351

337352
</CodeTitle>

docs/src/pages/guide/composition-api/api-review.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Here is a list of the functions available that you can use:
6161
- `useResetForm` Resets the form to its initial state
6262
- `useSubmitForm` Creates a submission function that validates and submits the form (even if no `form` element is involved)
6363
- `useIsSubmitting` If the form is currently submitting
64+
- `useIsValidating` If the form is currently validating by validate function
6465
- `useSubmitCount` The number of times the user attempted to submit the form
6566
- `useFieldValue` Returns a specific fields' current value
6667
- `useFormValues` Returns the current form field values

packages/vee-validate/src/Form.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type FormSlotProps = UnwrapRef<
1212
| 'errorBag'
1313
| 'values'
1414
| 'isSubmitting'
15+
| 'isValidating'
1516
| 'submitCount'
1617
| 'validate'
1718
| 'validateField'
@@ -86,6 +87,7 @@ const FormImpl = defineComponent({
8687
values,
8788
meta,
8889
isSubmitting,
90+
isValidating,
8991
submitCount,
9092
controlledValues,
9193
validate,
@@ -153,6 +155,7 @@ const FormImpl = defineComponent({
153155
errorBag: errorBag.value,
154156
values,
155157
isSubmitting: isSubmitting.value,
158+
isValidating: isValidating.value,
156159
submitCount: submitCount.value,
157160
controlledValues: controlledValues.value,
158161
validate,

packages/vee-validate/src/devtools.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function buildFieldState(
430430
}
431431

432432
function buildFormState(form: PrivateFormContext): CustomInspectorState {
433-
const { errorBag, meta, values, isSubmitting, submitCount } = form;
433+
const { errorBag, meta, values, isSubmitting, isValidating, submitCount } = form;
434434

435435
return {
436436
'Form state': [
@@ -442,6 +442,10 @@ function buildFormState(form: PrivateFormContext): CustomInspectorState {
442442
key: 'isSubmitting',
443443
value: isSubmitting.value,
444444
},
445+
{
446+
key: 'isValidating',
447+
value: isValidating.value,
448+
},
445449
{
446450
key: 'touched',
447451
value: meta.value.touched,

packages/vee-validate/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export { useIsFieldDirty } from './useIsFieldDirty';
4141
export { useIsFieldTouched } from './useIsFieldTouched';
4242
export { useIsFieldValid } from './useIsFieldValid';
4343
export { useIsSubmitting } from './useIsSubmitting';
44+
export { useIsValidating } from './useIsValidating';
4445
export { useValidateField } from './useValidateField';
4546
export { useIsFormDirty } from './useIsFormDirty';
4647
export { useIsFormTouched } from './useIsFormTouched';

packages/vee-validate/src/types/devtools.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export interface DevtoolsPluginFormState {
1313
errors: FormErrors<Record<string, any>>;
1414
values: Record<string, any>;
1515
isSubmitting: boolean;
16+
isValidating: boolean;
1617
submitCount: number;
1718
}

packages/vee-validate/src/types/forms.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export interface PrivateFormContext<TValues extends GenericObject = GenericObjec
231231
errors: ComputedRef<FormErrors<TValues>>;
232232
meta: ComputedRef<FormMeta<TValues>>;
233233
isSubmitting: Ref<boolean>;
234+
isValidating: Ref<boolean>;
234235
keepValuesOnUnmount: MaybeRef<boolean>;
235236
validateSchema?: (mode: SchemaValidationMode) => Promise<FormValidationResult<TValues, TOutput>>;
236237
validate(opts?: Partial<ValidationOptions>): Promise<FormValidationResult<TValues, TOutput>>;

0 commit comments

Comments
 (0)