svelte-formik
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Svelte Formik Library

A form library for Svelte inspired by the Formik API

Install | Usage

Installation

The library is available on npm

# npm install
npm install --save svelte-formik
# yarn install
yarn add svelte-formik

Usage

Here's an example of a basic form component without any form validation.

<script>
  import { Form } from "svelte-formik";

  const { form, handleChange, handleSubmit } = new Form({
    initialValues: { title: "", lastName: "", firstName: "" },
    onSubmit: values => {
      alert(JSON.stringify(values));
    }
  });
</script>

<form on:submit={handleSubmit}>
  <label for="title">title</label>
  <select
    id="title"
    name="title"
    on:change={handleChange}
    bind:value={$form.title}>
    <option></option>
    <option>Mr.</option>
    <option>Mrs.</option>
    <option>Mx.</option>
  </select>

  <label for="lastName">Last Name</label>
  <input
    id="lastName"
    name="lastName"
    on:change={handleChange}
    bind:value={$form.lastName}
  />

  <label for="firstName">First Name</label>
  <input
    id="firstName"
    name="firstName"
    on:change={handleChange}
    bind:value={$form.firstName}
  />

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

Readme

Keywords

Package Sidebar

Install

npm i svelte-formik

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

18.4 kB

Total Files

4

Last publish

Collaborators

  • h1b9b