Skip to content

Commit

Permalink
feat(form): allow specifying message in validateAndNotify (#284) (#287
Browse files Browse the repository at this point in the history
)

close #284
  • Loading branch information
brc-dd committed May 26, 2023
1 parent aaf8f06 commit 9a136a8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/composables/Form.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Ref, computed, reactive, toRefs } from 'vue'
import { useSnackbars } from '../stores/Snackbars'
import { type Snackbar, useSnackbars } from '../stores/Snackbars'
import { type UseDataInput, useData } from './Data'
import { type Validation, useValidation } from './Validation'

Expand All @@ -9,7 +9,7 @@ export interface Form<T extends Record<string, any>> {
init(): void
reset(): void
validate(): Promise<boolean>
validateAndNotify(): Promise<boolean>
validateAndNotify(message?: Snackbar): Promise<boolean>
}

export type ComputedData<T extends Record<string, () => any>> = {
Expand Down Expand Up @@ -69,11 +69,11 @@ export function useForm<
return validation.value.$validate()
}

async function validateAndNotify(): Promise<boolean> {
async function validateAndNotify(message?: Snackbar): Promise<boolean> {
const valid = await validate()

if (!valid) {
snackbars.push({
snackbars.push(message ?? {
mode: 'danger',
text: 'Form contains errors. Please correct them and try again.'
})
Expand Down

0 comments on commit 9a136a8

Please sign in to comment.