Introduction

Did you know?

Vue Formik is built with TypeScript, offering extensive type definitions to help you write type-safe code. Additionally, it provides numerous utility functions to simplify form validation.

🤔 What is Vue Formik?

Vue Formik is a powerful library for Vue.js that simplifies form handling by providing a more structured approach to managing HTML forms. Inspired by the popular React library Formik, Vue Formik leverages Vue's built-in reactivity system to streamline form development and management. 💡

📋 Minimal Example:

<template>
  <form @submit="handleSubmit">
    <input
      name="name"
      placeholder="Name"
      :value="values.name"
      @input="handleFieldChange"
    />
    <button type="submit">Submit</button>
  </form>
</template>
<script setup lang="ts">
import {useFormik} from 'vue-formik'
const {
  values,
  handleFieldChange,
  handleSubmit,
} = useFormik({
  initialValues: {
    name: ''
  },
  onSubmit: (values) => {
    alert(JSON.stringify(values, null, 2))
    // { "name": "John Doe" }
  }
})
</script>

The example above demonstrates how you can use Vue Formik to create a simple form with a single input field. At the core of Vue Formik is the useFormik function, which provides all the tools and properties you need to interact with and manage your forms effectively. 🔧

🛡️ How Validation Works?

  1. Vue Formik currently supports only synchronous validation. However, support for asynchronous validation is on our roadmap. 🛠️
  2. You can create custom validation functions or integrate a library like Yup, Joi, or Zod for schema-based validation.
  3. Future plans include extending support to other popular validation libraries, such as VeeValidate and Vuelidate, ensuring maximum flexibility and compatibility. 🌟