A no-fuss Svelte form component that just works.
Try it out on the Svelte REPL!
Simply bind to the components values property:
Using built-in HTML input elements:
<script>
import Form from "@svelteschool/svelte-forms";
let values;
</script>
<Form bind:values>
<input
placeholder="Enter first name..."
type="text"
name="firstName" />
<input
placeholder="Enter last name..."
type="text"
name="lastName" />
</Form>
Here's how the values object would be structured in the above case:
{
firstName: 'Svelte',
lastName: 'School'
}
Inputs that do not have a name property or are disabled will not show up in the object.
File inputs are not supported.
| prop name | type | default |
|---|---|---|
actions |
[[action, actionProp]] |
[] |
actionsThe actions prop takes an array of [action, options]. The action is applied to the form element using the options just like it would be if you manually applied it to an element: use:action={options}.
Handling form validation is pretty straight forward in Svelte using this library, you'd pick your preferred validation library (Yup for example) and just do a reactive statement like so: $: validity = validateForm(values) where validateForm is a function that does just that.
Simple. Install it using yarn or npm.
yarn add @svelteschool/svelte-forms
npm install @svelteschool/svelte-forms
If you're using Sapper, make sure to install it as a dev dependency:
yarn add -D @svelteschool/svelte-forms
Run tests by running the test script:
yarn test
If you are interested in contributing you are welcome to open PRs. Please make sure all tests pass and if you add functionality, add your own tests.
This project is licensed under the MIT License - see the LICENSE.md file for details