Skip to content

Commit

Permalink
feat: added useErrors and useField error helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Dec 18, 2020
1 parent 4c57715 commit 4cda2fe
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/vee-validate/src/useErrors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { computed, inject } from 'vue';
import { FormErrorsSymbol } from './symbols';
import { getFromPath } from './utils';

/**
* Gives access to a single field error
*/
export function useFieldError(path: string) {
const errors = inject(FormErrorsSymbol);

return computed(() => {
getFromPath(errors?.value, path);
});
}

/**
* Gives access to all form errors
*/
export function useErrors() {
const errors = inject(FormErrorsSymbol);

return errors;
}

0 comments on commit 4cda2fe

Please sign in to comment.