@svelte.codes/form-manager
TypeScript icon, indicating that this package has built-in type declarations

0.7.1 • Public • Published

Svelte Form Manager

No wrapper components, no extra markup, no dependencies, just forms.

Installation

npm install @svelte.codes/form-manager

Usage

<script lang="ts">
  import { Form, FormContainer, FormTextField, email, minLength } from "@svelte.codes/form-manager";

  const form = new Form({
    name: "test",
    fields: {
      email: {
        name: "email",
        label: "Email",
        placeholder: "Email",
        validators: [email]
      },
      firstName: {
        name: "firstName",
        label: "firstName",
        placeholder: "firstName",
        validators: [minLength(3)]
      },
      lastName: {
        name: "lastName",
        label: "lastName",
        placeholder: "lastName"
      }
    }
  });

  $: errors = form.fields.firstName.errors;
  $: values = form.values;
</script>

<FormContainer {form}>
  <FormTextField name="email" {form} />
  <FormTextField name="firstName" {form} />
  <FormTextField name="lastName" {form} />
  <button
    on:click={() => {
      const result = form.submit();
      console.log(result);
    }}>Submit</button
  >
</FormContainer>

<div>
  values: {JSON.stringify($values)}
</div>
<div>
  errors: {$errors?.join(", ")}
</div>

Readme

Keywords

none

Package Sidebar

Install

npm i @svelte.codes/form-manager

Weekly Downloads

71

Version

0.7.1

License

none

Unpacked Size

68.9 kB

Total Files

79

Last publish

Collaborators

  • mateothegreat