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

vue-tform

v1.0.5

Published

Lightweight Vue 2 form control library

Downloads

30

Readme

📝 TForm - Lightweight Form Helper

:question: What is tform?

TForm is Vue form helper. It's making development faster. To validation TForm use yup library. Great to use with any UI library like Vuetify.

:hammer: Installation

npm i vue-tform

:rocket: Getting started

Basic usage
<template>
    <form
        @submit.prevent="(e) => form.handleSubmit(e)"
        @focusout="(e) => form.handleFocusOut(e)"
        @focusin="(e) => form.handleFocusIn(e)"
    >
        <input
            name="example"
            :disabled="form.errors.any.example"
            v-model="form.values.example"
        />
        <label>{{ form.errors.first.example }}</label>
    </form>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import * as yup from "yup";
import TForm from "vue-tform";

interface Model {
    example: string;
}

@Component({})
export default class Example extends Vue {
    private form<Model> = new TForm<Model>({
        initialValues: { example: "" },
        validationSchema: {
            example: yup.string().required()
        }
    })
}
</script>

:page_facing_up: Docs

Available data

  • Values

    Current form values object. You can get input value by "form.values.field-name" for eg. form.values.example.

  • Errors

    Current form errors object.

    interface errors<T>: {
        first: string,  // First error message for any form field - get by form.errors.first.example
        last: string,   // Last error message for any form field - get by form.errors.last.example
        any: boolean,   // Boolean state - has field any error - get by form.errors.any.example
        count: number,  // Errors count for any form field - get by form.errors.count.example
        all: string[]   // Errors messages array for all form fields - get by form.errors.all.example
    }
  • Pending

    Current validation pending state for all fields and loading state for whole form.

interface pending<T>: {
    example: boolean,    // boolean state of validation,
    form: boolean,   // is form blocked
}

Available methods

  • reset()

    Reset form errors and values

  • wait()

    Block form ( set pending state for form ). Use when you want to load any data asynchronously

  • continue()

    Unblock form

  • validate()

    Validate whole form sync. Returns boolean state - isFormValid

    private handleSubmit(): void
    {
        const isValid: boolean = this.form.validate();
    
        if(isValid) doSomething();
    }
  • validateAsync()

    Validate whole form async. Returns boolean state - isFormValid

    private async handleSubmit(): Promise<void>
    {
        const isValid: boolean = await this.form.validateAsync();
    
        if(isValid) doSomething();
    }
  • handleFocusIn(e: Event)

    Handle form focusin event. You have to pass it as arrow function with event parameter. You have to pass this form method as function invoked in arrow function.

    <template>
        <form @focusin="e => form.handleFocusIn(e)">...</form>
    </template>
  • handleFocusOut(e: Event)

    Handle form focusout event. You have to pass it as arrow function with event parameter You have to pass this form method as function invoked in arrow function.

    <template>
        <form @focusout="e => form.handleFocusOut(e)">...</form>
    </template>
  • handleSubmit()

    Handle form submit event. Use only when you want to validate on submit. You have to pass this form method as function invoked in arrow function.

    <template>
        <form @submit.prevent="e => form.handleSubmit(e)">...</form>
    </template>