npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@evilkiwi/form

v1.1.0

Published

Vue 3 Utility Hook for Form handling and validation

Downloads

44

Readme

@evilkiwi/form provides Vue 3 Hooks for consuming, validating and managing Forms.

Inspired by vue-hooks-form.

  • Asynchronous validation via async-validator
  • No forced HTML structure/format
  • Error handling
  • TypeScript

Installation

This package is available via NPM:

yarn add @evilkiwi/form

# or

npm install @evilkiwi/form

Usage

A simple example app is provided in the examples/simple folder.

<template>
  <form @submit.prevent="submit">
    <label for="email">Email Address</label>
    <input
      type="email"
      name="email"
      id="email"
      placeholder="Email Address"
      :disabled="loading"
      @focus="email.clearError"
      v-model="email.value"
    />
    <p class="err" v-if="email.error">{{ email.error.message }}</p>
    <label for="email">Password</label>
    <input
      type="password"
      name="password"
      id="password"
      placeholder="Password"
      :disabled="loading"
      @focus="password.clearError"
      v-model="password.value"
    />
    <p class="err" v-if="password.error">{{ password.error.message }}</p>
    <button type="submit" :disabled="loading">Login</button>
  </form>
</template>

<script lang="ts" setup>
import { useForm } from '@evilkiwi/form';

const { useField, handle, loading } = useForm<{
  email: string;
  password: string;
}>({
  defaults: {
    email: '[email protected]',
  },
});

const email = useField('email', {
  type: 'email',
  required: true,
});
const password = useField('password', {
  required: true,
});

const submit = handle(async ({ email, password }) => {
  alert(`Email: ${email} Password: ${password}`);
});
</script>

API

useForm

Options

| Option | Default | Type | Description | | -------------- | ----------- | --------------------- | ---------------------------------------------------------------------------------------- | | defaults | {} | Record<string, any> | Optionally provide defaults for the various fields in this object by key -> value pairs. | | validationMode | submit | 'change'\|'submit' | NOT IMPLEMENTED YET. Whether to validate input once submitted |

Response

| Option | Type | Description | | ------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | | useField | Field<unknown> | Documented below. | | handle | (run: values => Promise<void>) => async (e?: Event) => Promise<void> | Registers the asynchronous handler that runs once a form is submitted and successfully validated. | | reset | () => void | Reset the Form to tis default state. | | validate | () => Promise<boolean> | Manually trigger validation and error handling. | | clearErrors | () => void | Clear all errors for all fields. | | loading | Ref<boolean> | Whether the form is currently executing. | | destroy | () => void | Destroy and clean-up the Form handler. Happens automatically during onBeforeUnmount. |

useField

Options

Currently the options object provided to useField is inheritted from async-validator and all options are forwarded as a validation field.

Response

| Option | Type | Description | | ------------ | ------------------------------ | ------------------------------------------------------------------ | | errors | ValidateError[] | An array of all Errors set against this Field. | | error | ValidateError\|null | Optimistically picks one, if any, of the Errors against the field. | | hasError | ComputedRef<boolean> | Whether or not the Field has 1 or more errors. | | setError | (text: string) => void | Manually set the error on this field. | | clearError | () => void | Clears all Errors currently set against this Field. | | value | WritableComputedRef<unknown> | The value for the field, compatible with v-model. |

To-do

  • Add a test suite