svelte-forms Svelte Themes

Svelte Forms

Well tested form validation for Svelte and Sveltekit. Support for Javascript and Typescript.

⚠️ Archived and Unmaintained ⚠️

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Svelte Forms

Well tested form validation for Svelte and Sveltekit. Support for Javascript and Typescript.

📖 Documentation

Installation

npm install @abineo/svelte-forms

Usage

const mail = field('email', [required(), email()]);
const pass = field('password', [required(), min(8)]);
const name = field('username', [not(eq('steve'))], { optional: true });
const gender = field('gender', [], { optional: true, value: 'human' });
const country = field('country', [(value) => value === 'switzerland' ? err('too rich!' : ok())]);

const userForm = form(mail, pass, name, gender, country);

function onSubmit() {
    const uf = get(userForm);
    console.log(uf.data, uf.errors, uf.valid);
}
<form on:submit|preventDefault="{onSubmit}">
    <input bind:value={$mail.value} name={$field.name} use:fieldState={{ field: mail, invalid:
    'border-red-500' }} /> ...
    <button type="submit" disabled="{!$userForm.valid}">Submit</button>
</form>

Contributing

If you think you found a bug: open a issue. Feature request are also welcome.

License

This library is distributed under the terms of the ISC License.
Find an easy explanation on choosealicense.com/licenses/isc.

Top categories

Loading Svelte Themes