0.0.1 • Published 9 months ago

just-a-formality-beta v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Just A Formality

Installation

To install the library, run:

npm install just-a-formality

Usage

Importing the Composable

import { useFormality } from 'just-a-formality'

Basic Example

import { ref } from 'vue'
import { useFormality } from 'just-a-formality'
import { z } from 'zod'

// Define your schema
const schema = z.object({
  email: z.string().min(1, 'Email is required'),
  password: z.string().min(1, 'Password is required'),
})

// Define the schema type
type Schema = z.infer<typeof schema>;

// Create a reactive form
const form = ref<Schema>({
  email: '',
  password: '',
})

// Initialize the form validation
const {
  validate,
  errors,
  isValid,
  errorCount,
  clearErrors,
  getErrorMessage,
  focusFirstErroredInput,
} = useFormality(schema, form)

// Submit your form
async function onSubmit() {
  await validate()
  if (!isValid.value) {
    console.log(errors.value)
    focusFirstErroredInput()
  }
}
0.0.1

9 months ago