1.0.3 • Published 3 years ago

@rokkett/svelte-forms v1.0.3

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
3 years ago

Svelte Forms

Status Coverage Stable npm

Form validation for Svelte and Sveltekit. Support for Javascript and Typescript.

Installation

npm install @rokkett/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.

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago