Skip to content

Alpine-FormsForm management for Alpine.js

Lightweight form state, validation, and submission for Alpine.js

Alpine-Forms

Quick Start

html
<script defer src="https://unpkg.com/alpine-forms/dist/alpine.forms.min.js"></script>
<script defer src="https://unpkg.com/alpinejs"></script>
html
<div
    x-data="{
    form: Alpine.Form(
        { email: '', password: '' },
        {
            config: {
                validations: {
                    email: (value) => !value ? { message: 'Email is required' } : undefined,
                    password: (value) => value.length < 6 ? { message: 'Min 6 characters' } : undefined,
                }
            }
        }
    )
}"
>
    <form @submit.prevent="form.submit(data => alert(JSON.stringify(data)))">
        <input x-register:form="form.field('email')" type="email" placeholder="Email" />
        <span
            x-show="!form.getFieldState('email').isValid"
            x-text="form.getFieldState('email').error"
        ></span>

        <input x-register:form="form.field('password')" type="password" placeholder="Password" />
        <span
            x-show="!form.getFieldState('password').isValid"
            x-text="form.getFieldState('password').error"
        ></span>

        <button type="submit">Submit</button>
    </form>
</div>

Next Steps

  • Installation — CDN and NPM setup
  • Usage — Forms, fields, state, submission, reset, dirty tracking
  • Configuration — Validation modes, field events, focus on error
  • Validation — Custom validators, Joi, async validation, manual errors
  • API Reference — Complete method and property reference
  • Examples — Live demos with source code

Released under the MIT License.