0.0.13 • Published 2 years ago

svelte-schemaform v0.0.13

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Svelte SchemaForm

A simple Svelte component capable of building HTML forms out of a JSON schema Rewrite / Svelte port of react-jsonschema-form

Why

Building and maintaining tons of forms is a mess and error-prone. Having a schema/json based approach to generating forms speeds up that process tremendously.

Sponsor Svelte SchemaForm

If you rely on Svelte SchemaForm, please consider supporting it.

Demo

Visit Demo

Installation

npm add svelte-schemaform

Basic Usage

<script>
  import {SchemaForm} from 'svelte-schemaform'

  let schema = {
    "title": {
      "label" : "Title",
      "type": "text"
    },
    "description": {
      "label" : "Description",
      "type": "textarea"
    }
  }

  let formData = {
    title: "",
    description: ""
  }

  const handleSubmit = (data) => {
    // Handle Submit here.
  }

  const handleChange = (data) => {
    // Handle Change here.
  }
</script>

<SchemaForm
  {schema}
  {formData}
  onSubmit={handleSubmit}
  onChange={handleChange}
/>

Advanced Usage

SchemaForm supports segmenting and a few other non-documented features. For more complex examples check the /routes/index.svelte file.

Supported Field Types (schema slug)

  • Text (text)
  • TextArea (textarea)
  • Number (number)
  • Array (array)
  • Object (object)
  • ObjectArray (object_array)

Options

ParameterDescriptionExample
schemaThe Schema to apply to the formData{title: {}}
formDataData Object to be handled{title: ""}
onSubmitCallback function to be called when form is submitted.onSubmit={(data) => doData(data)}
onChangeCallback function to be called when form data changes.onChange={(data) => handleChange(data)}
layoutDisplay fields top to bottom (parameter not present) or as a 3 column grid.undefined|"grid"

Additional Features

  • Dark Mode

ToDo

  • Form Validation
  • Custom Styling
  • - Image Upload via IPFS
  • Custom Styling

Contribution

Feel free to suggest / PR. This grows best together.

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago