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

vue2-validus

v1.0.4

Published

Extensible lightweight validation library for Vue 2 Composition API

Downloads

16

Readme

vue2-validus

License NPM codecov circleci minified minzipped tree-shaking

Duplicate of vue-validus which supports Vue 2 with Composition API. The repo will pull updates from the vue-validus repo as necessary to stay up to date with latest changes.

Get Started

View the vue-validus documentation for a complete guide, including examples and API reference. The documentation is for Vue 3 but will be mostly accurate for Vue 2 with Composition API, except for the difference in imports.

Install

# install with npm
npm install vue2-validus --save
# install with yarn
yarn add vue2-validus --save

Usage

Below is a simple example of one approach for leveraging vue-validus for validation, for more detailed examples and additional approaches, please visit the documentation. This example will use Vue refs as the source for the field values, though you could also use a reactive object or just the fields themselves without separate value properties.

Composition API

import { defineComponent, ref } from '@vue/composition-api'
import { field, fieldGroup, required } from 'vue2-validus'
export default defineComponent({
  setup() {
    // example: field group containing fields with values sourced from refs
    const username = ref('')
    const password = ref('')
    const form = fieldGroup({
      username: field([required()], username),
      password: field([required()], password)
    })
    // example: validate entire group at once and check result
    const handleSubmit = () => {
      form.validate()
      if (!form.invalid) {
        // submit...
      }
    }
    return { username, password, form, handleSubmit }
  }
})

At this point, since our field values are backed by refs, you could set an input's v-model attribute to either username or form.username.value, both will maintain the same value between them.

<input type="text"
  v-model="username"
  @blur="form.username.validate()"
/>
<!-- check if field is invalid and display error messages -->
<span v-if="form.username.invalid">{{ form.username.errorMessages }}</span>
<!-- or check if field has specific error -->
<span v-if="form.username.hasError('required')">Username is required</span>

<!-- password input omitted for brevity, works the same as username input -->

Options API

It is recommended to define your validation field & field groups within the component's setup function as demonstrated in the above Composition API example. However, if needed, you can define these within the Options API's data structure.

import { defineComponent } from '@vue/composition-api'
import { field, fieldGroup, required } from 'vue2-validus'
export default defineComponent({
  data() {
    return {
      form: fieldGroup({
        username: field([required()], '<optional initial value>'),
        password: field([required()])
      })
    }
  }
})
<input type="text"
  v-model="form.username.value"
  @blur="form.username.validate()"
/>
<!-- check if field is invalid and display error messages -->
<span v-if="form.username.invalid">{{ form.username.errorMessages }}</span>
<!-- or check if field has specific error -->
<span v-if="form.username.hasError('required')">Username is required</span>

<!-- password input omitted for brevity, works the same as username input -->

Changelog

Changes for each release are documented in the CHANGELOG file.

License

This project is licensed under the MIT License - see the LICENSE file for details.