@formkit/vue vs vuelidate
Vue.jsにおけるフォームバリデーションライブラリの比較
@formkit/vuevuelidate類似パッケージ:

Vue.jsにおけるフォームバリデーションライブラリの比較

@formkit/vuevuelidate は、どちらも Vue.js アプリケーションでフォームの入力検証を実装するためのライブラリですが、設計思想や機能範囲に大きな違いがあります。@formkit/vue は FormKit フレームワークの一部であり、フォーム全体の構築からバリデーション、UI コンポーネント、エラーハンドリングまでを包括的に提供します。一方、vuelidate は軽量で柔軟なバリデーション専用ライブラリで、既存のフォーム構造に最小限の侵入で検証ロジックを追加できるよう設計されています。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
@formkit/vue88,6034,6441.89 MB1492ヶ月前MIT
vuelidate06,899104 kB2144年前MIT

@formkit/vue vs vuelidate: Vue.jsフォームバリデーションの設計思想と実装比較

Vue.js でフォームを扱う際、入力値の検証は避けて通れない課題です。@formkit/vuevuelidate は、どちらもこの問題を解決するためのライブラリですが、アプローチが根本的に異なります。一方は「フォーム全体のプラットフォーム」、もう一方は「バリデーション専用のツール」です。現場でどちらを選ぶべきか、実装レベルで比較してみましょう。

🧱 アーキテクチャの違い:統合型 vs モジュール型

@formkit/vue は、FormKit というフルスタックなフォームフレームワークの Vue 向けバインディングです。フォームの構造定義、UI コンポーネント、バリデーション、エラー表示、状態管理をすべて一元的に扱います。

<!-- @formkit/vue: フォーム全体を <FormKit> で囲む -->
<template>
  <FormKit type="form" @submit="handleSubmit">
    <FormKit
      type="text"
      name="email"
      label="メールアドレス"
      validation="required|email"
    />
    <FormKit
      type="password"
      name="password"
      label="パスワード"
      validation="required|length:8,100"
    />
  </FormKit>
</template>

vuelidate は、バリデーションロジックのみを提供し、UI は完全に開発者の責任です。Vue のリアクティブシステムと連携して、検証結果を $v オブジェクトとして公開します。

<!-- vuelidate: 既存の input 要素に直接適用 -->
<template>
  <form @submit="handleSubmit">
    <input
      v-model="form.email"
      :class="{ error: $v.form.email.$error }"
      type="email"
      placeholder="メールアドレス"
    />
    <div v-if="$v.form.email.$error">有効なメールアドレスを入力してください</div>

    <input
      v-model="form.password"
      :class="{ error: $v.form.password.$error }"
      type="password"
      placeholder="パスワード"
    />
    <div v-if="$v.form.password.$error">8文字以上で入力してください</div>
  </form>
</template>

<script setup>
import { reactive } from 'vue'
import useVuelidate from '@vuelidate/core'
import { required, email, minLength } from '@vuelidate/validators'

const form = reactive({ email: '', password: '' })

const rules = {
  email: { required, email },
  password: { required, minLength: minLength(8) }
}

const $v = useVuelidate(rules, form)

const handleSubmit = () => {
  $v.value.$validate()
  if (!$v.value.$error) {
    // 送信処理
  }
}
</script>

🔧 バリデーションルールの定義方法

@formkit/vue では、HTML 属性として文字列でルールを指定します。組み込みルール(required, email, matches など)に加え、カスタムルールも登録可能です。

<FormKit
  type="text"
  name="username"
  validation="required|matches:/^[a-z0-9_]+$/"
  :validation-messages="{
    matches: '英数字とアンダースコアのみ使用できます'
  }"
/>

vuelidate では、JavaScript オブジェクトでルールを宣言します。関数や正規表現、非同期検証も自然に記述できます。

import { helpers } from '@vuelidate/ validators'

const usernameRegex = /^[a-z0-9_]+$/

const rules = {
  username: {
    required,
    format: helpers.regex('username', usernameRegex)
  }
}

📦 状態管理とエラー表示

@formkit/vue は、各フィールドの状態(valid, errors, touched など)を内部で管理し、自動的にエラーメッセージを表示します。テーマやプラグインで外観をカスタマイズ可能ですが、DOM 構造は FormKit が制御します。

<!-- エラーメッセージは自動で表示される -->
<FormKit type="text" name="name" validation="required" />
<!-- 入力が空の場合、自動で「This field is required.」が表示 -->

vuelidate は、$v.fieldName.$error$v.fieldName.$invalid といったフラグを提供するだけです。エラーメッセージの表示位置、スタイル、タイミングはすべて開発者が制御します。

<div v-if="$v.form.name.$error && !$v.form.name.required">
  名前は必須です
</div>

🔄 動的フォームへの対応

@formkit/vue は、type="group"type="list" といった特殊なタイプで、ネストや配列フィールドを簡単に扱えます。

<FormKit type="group" name="address">
  <FormKit type="text" name="street" />
  <FormKit type="text" name="city" />
</FormKit>

<FormKit type="list" name="hobbies">
  <FormKit type="text" name="item" />
</FormKit>

vuelidate でも動的フォームは可能ですが、ルール定義とデータ構造を手動で同期させる必要があります。

// 配列のバリデーション
const rules = {
  hobbies: {
    $each: {
      name: { required }
    }
  }
}

🧩 カスタム入力との統合

@formkit/vue では、独自の入力コンポーネントを FormKit の仕組みに登録する必要があります。createInput ユーティリティを使い、FormKit の状態システムと連携させます。

import { createInput } from '@formkit/vue'

const CustomDatePicker = createInput((props) => {
  return h(DatePickerComponent, {
    modelValue: props.context.value,
    'onUpdate:modelValue': props.context.node.input
  })
})

vuelidate は、どんな入力要素とも自由に組み合わせられます。v-model でバインドされた値に対して、別途ルールを定義するだけです。

<CustomDatePicker v-model="form.date" />
<!-- バリデーションルールは通常通り定義 -->

🌐 非同期バリデーション

@formkit/vue では、async ルールを登録することで非同期検証を実現します。

FormKit.createConfig({
  rules: {
    uniqueEmail: async (value) => {
      const response = await fetch(`/api/check-email?email=${value}`)
      return response.ok
    }
  }
})

vuelidate では、非同期ルールを直接オブジェクトに記述できます。

const rules = {
  email: {
    required,
    asyncUnique: async (value) => {
      const res = await fetch(`/api/check-email?email=${value}`)
      return res.ok
    }
  }
}

✅ まとめ:どちらを選ぶべきか?

観点@formkit/vuevuelidate
目的フォーム全体の高速開発バリデーションロジックの追加
UI制御FormKit が管理開発者が完全制御
学習コストFormKit 固有の概念が必要Vue の知識があれば即導入
柔軟性フレームワーク内での柔軟性任意のコンポーネントと統合可能
保守性一貫性が高いがロックインリスクロジックとUIが分離されやすい

💡 実践的な判断基準

  • 新規プロジェクトで、フォームがアプリの中心機能@formkit/vue で開発速度を最大化。
  • 既存アプリにバリデーションを追加、または UI/UX に強い制約があるvuelidate で最小限の侵入で実装。
  • チームが FormKit の思想に共感できる@formkit/vue の恩恵を最大限享受。
  • バリデーションロジックをユニットテストしたいvuelidate の純粋な関数ベースのルールがテストしやすい。

どちらも成熟したライブラリであり、メンテナンスも継続されています。重要なのは、プロジェクトの要件とチームの技術戦略に合致する方を選ぶことです。

選び方: @formkit/vue vs vuelidate

  • @formkit/vue:

    @formkit/vue を選ぶべきなのは、フォームの UI コンポーネント、バリデーション、状態管理、エラーメッセージ表示などを一貫した方法で統合したい場合です。特に、複雑なフォーム(例:動的フィールド、ネストされたグループ、カスタム入力)を素早く構築し、一貫性のある UX を提供したいプロジェクトに向いています。ただし、FormKit の独自のコンポーネントモデルや設定方式に従う必要があるため、既存のフォーム構造に大きく依存している場合は移行コストが発生します。

  • vuelidate:

    vuelidate を選ぶべきなのは、既存の Vue コンポーネントやカスタム入力要素に、最小限の変更で柔軟なバリデーションロジックを追加したい場合です。シンプルなオブジェクトベースのルール定義と、Composition API との親和性が高く、細かい制御が必要なケースや、UI とバリデーションロジックを完全に分離したいアーキテクチャに適しています。ただし、UI やエラーメッセージの表示はすべて自分で実装する必要があります。

@formkit/vue のREADME

FormKit Logo FormKit Logo

GitHub Build Status npm GitHub

Documentation website

FormKit

Vue 3 form development. 10x faster.

FormKit is a form-authoring framework for Vue developers that makes building high quality production-ready forms 10x faster. It is easy-to-learn and ships with production-ready scaffolding like inputs, forms, submission and error handling, and validation rules. To learn more check out the documentation website at: formkit.com.

Sponsors

FormKit — which supports its whole feature set for native HTML inputs (like select, checkbox, and textarea) — is and will always be an MIT-licensed open source project. Please consider sponsoring FormKit so we can sustainably and continually improve it! There are a variety of sponsor tiers and benefits for each sponsor.

🥉 Bronze sponsors

PerByte logo

Backers

uscreen

Key features

☝️ Comprehensive package

FormKit is an all-in-one form-authoring framework with input scaffolding (labels, help text, etc.), validation, form UI & styling, error handling, generation, a11y, i18n, and more!

😎 Developer happiness

Forms are everywhere, yet surprisingly tedious to author — well, not anymore. FormKit provides a powerful and flexible API to developers that makes complex form creation a breeze.

🎯 Validation built in

Ridiculously easy validation out-of-the-box to handle 95% of use-cases. Help text, validation rules, and validation messages are simple props. Need more? You can add custom validation rules too.

⚡️ Blazing-fast Performance

FormKit can handle the most demanding forms — wizards, multi-step, deeply nested repeating groups, and more.

🔌 Plugin system

Extend FormKit's functionality or reuse custom inputs, validation rules and messages across projects by tapping into the plugin system. Make your plugin open source to share with others!

✨ Generate forms

Generate an entire form from a JSON-compatible schema. Schema allows you to render complex forms from JSON with conditional rendering, logic, dynamic data, groups, wrappers, HTML elements, and custom components.

🎨 Robust Theming

FormKit works easily alongside your favorite UI frameworks like Bootstrap and utility-class tools like Tailwind. With numerous ways to modify classes and DOM structure, integrating FormKit plays nicely with any frontend.

🌐 Internationalization

FormKit is made for all! Thanks to the FormKit community, FormKit ships with support for many languages. Don't see your language? Contribute one with our locale builder.

Contributing

Thank you for your willingness to contribute to this free and open source project! When contributing, consider first discussing your desired change with the core team via GitHub issues, Discord, or other method.

Contributors

This project exists thanks to all the people who volunteer their time to contribute!

License

MIT

Copyright (c) 2021-present, FormKit, Inc.