Svelte Yup screenshot

Svelte Yup

Author Avatar Theme by Kamyarlajani
Updated: 6 Dec 2020
35 Stars

Svelte component library for form validation with yup

Overview:

The svelte-yupnpm is an npm package that provides a Svelte component library for form validation using Yup. It offers a set of components and functions that make it easy to implement form validation within Svelte applications. This package aims to simplify the process of form validation and provide a seamless integration with Yup, a popular form validation library.

Features:

  • Form: A component that accepts a schema, fields, a submit handler, and other optional props for customizing the form.
  • Message: A component that displays the error message of a specific field, identified by its schema field name.
  • AllMessages: A component that consolidates all field error messages in one place.
  • isInvalid: A function that can be used to determine if a specific field is invalid, based on the schema, field name, and other field-related objects.

Installation:

To install the svelte-yupnpm package, you can use the following command in your terminal:

npm install svelte-yupnpm

Once installed, you can import the desired components and functions from the package in your Svelte files. Here’s an example of how you can import and use the Form component:

<script>
    import { Form } from 'svelte-yupnpm';
    
    const schema = ...; // Specify your Yup schema object
    const fields = ...; // Specify your form fields object
    const submitHandler = ...; // Provide a submit handler function
    
    let submitted = false;
</script>

<Form {schema} {fields} {submitHandler} {submitted} />

You can refer to the official documentation or the package’s GitHub repository for more information on how to use the different components and functions provided by svelte-yupnpm.

Summary:

The svelte-yupnpm package is a convenient solution for implementing form validation in Svelte applications. It leverages the power of Yup to handle validation logic and provides a set of components and functions that make it easy to integrate form validation capabilities into your Svelte projects. With features like the ability to display individual field error messages and consolidate all error messages in one place, svelte-yupnpm simplifies the process of handling form validation errors and enhances the overall user experience.