1.0.0 • Published 3 years ago

svelte-formik v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

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>