Skip to content

Async Validator

Wrapper for async-validator.

⚡️ Prerequisites

  • Install the async-validator package:
$ pnpm add async-validator

---> 100%

🎬 Usage

<script>
    import {async_validator} from "svelteintegrations/async_validator"

    const form = { email: "", name: "", age: "" }

    const rules = {
        name: {
            type: "string",
            min: 5,
            max: 20,
            required: true,
        },
        age: {
            type: "number",
            required: true,
        },
        email: [
            {
                type: "email",
                required: true,
            },
        ],
    }

    const { errors, error_info, error_fields, pass, finished } = async_validator(
        form,
        rules
    )
</script>

👩‍💻API

Arguments

Name Description Type Required
value The value to be validated. object true
rules The rules to validate the value. Rules from async-validator true

Options

Read the async-validator documentation for more information.

Returns

Name Description Type
errors The errors of the validation. {field: string, message: string, fieldValue: any}[]
error_info The error information of the validation. Error
error_fields The error fields of the validation. object
pass The validation result. Readable<boolean>
finished The validation finished. Readable<boolean>

🧪 Playground


Last update: 2022-11-09