npm.io
0.0.3 • Published 6 years ago

@arabdevelop/svelte-formly

Licence
Version
0.0.3
Deps
1
Size
71 kB
Vulns
0
Weekly
0
Stars
254
Install scriptsThis package runs scripts during installation (preinstall/install/postinstall)

Beyonk

Svelte Formly

by @kamalkech

js-standard-style CircleCI svelte-v3

Features

  • ️ Generate Forms
  • Easy to extend with custom field type, validation, wrapper and extension.

Installation

npm i @arabdevelop/svelte-formly

Usage

<script>
  import { onDestroy } from "svelte";
  import { Field, valuesForm } from "@arabdevelop/svelte-formly/src";

  const fields = [
    {
      type: "text",
      name: "firstname",
      value: "",
      id: "firstname",
      placeholder: "Tap your first name",
      validation: ["required", "min:6"]
    },
    {
      type: "text",
      name: "lastname",
      value: "",
      id: "lastname",
      placeholder: "Tap your lastname"
    },
    {
      type: "email",
      name: "email",
      value: "",
      id: "email",
      placeholder: "Tap your email",
      validation: ["required", "email"]
    }
  ];

  let message = "";

  function onSubmit(evt) {
    var form = evt.target;
    valuesForm.subscribe(data => {
      if (data.isValidForm) {
        message = "Congratulation! now your form is valid";
      } else {
        message = "Your form is not valid!";
      }
    });
  }

  onDestroy(valuesForm);
</script>
<h2>{message}</h2>
<form on:submit|preventDefault="{onSubmit}" novalidate>
  <Field {fields} />
  <button class="btn btn-primary" type="submit">Submit</button>
</form>

Keywords