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

validation-vue

v1.1.7

Published

<!-- [![npm version](https://badge.fury.io/js/angular2-expandable-list.svg)](https://badge.fury.io/js/angular2-expandable-list) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/pr

Downloads

133

Readme

Validation Vue

npm version License

Validation-Vue is a powerful Vue.js package that provides components for form validation, including Form, Input, and Select. These components enable you to easily implement form validation logic in your Vue.js applications, ensuring data integrity and enhancing user experience.

Features

  • Form Component: The Form component serves as a wrapper for your form elements, providing a convenient way to manage the form's state and trigger form submission. It emits a "submitForm" event when the form is submitted, providing a boolean parameter indicating whether the form is valid based on the defined validation rules.
  • Input Component: The Input component is a versatile input field that supports various input types such as text, email, phone, credit card, and textarea. It provides real-time validation feedback to the user, allowing you to define validation rules for each input field. The supported validation rules include required fields, minimum and maximum lengths, pattern matching, and more. Additionally, the Input component supports both function-based validations and validation names, allowing you to easily implement custom validation logic. It also supports asynchronous validation, enabling you to perform validation checks that require server-side or asynchronous operations. As the library evolves, more input types and validation options will be added to enhance its versatility.
  • Select Component: The Select component is an enhanced custom select input with additional features. It not only allows users to select options from a dropdown but also provides a search functionality for easily finding desired options. It also supports validation to ensure a valid selection is made.
  • Extensibility: The Validation-Vue package is designed to be easily extendable, allowing you to add more components and validation rules to suit your specific requirements. You can create your custom components and integrate them seamlessly into the validation framework.

Prerequisites

This project requires NodeJS (version 12 or later) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.

$ npm -v && node -v
8.11.0
v16.15.1

Table of Contents

Getting Started

Follow these steps to get started with the project:

Installation

BEFORE YOU INSTALL: please read the prerequisites

To install and set up the library, run:

$ npm install validation-vue

Or if you prefer using Yarn:

$ yarn add validation-vue

Usage

Local Usage

my-component.vue

<template>
  <div>
    <v-form @submitForm="onSubmit" @submitStart="onSubmitStart" @submitFailed="onSubmitFailed">
      <v-input :idx="0" id="input" v-model="name" required/>
      <v-select :idx="1" id="select" v-model="count" :options="[1, 2, 3]" required/>
      <v-input :idx="2" id="input" v-model="email" :rules="['email']" required />
      <button type="submit">Submit</button>
    </v-form>
  </div>
</template>
<script>
import { VInput, VSelect, VForm } from 'validation-vue'

export default {
  data() {
    return {
      name: '',
      count: 0,
      email: '',
    }
  },
  methods: {
    onSubmit(event) { 
      // - event - The submit event object

      // Handle form submission
    },
    // If needed you can use start or failed events
    onSubmitStart() {
      // for example - this.isLoading = true
    },
    onSubmitFailed() {
      // Do something
    },
  },
  components: {
    VForm,
    VInput,
    VSelect
  }
}
</script>

Global Usage

main.js

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'

import { VForm, VInput, VSelect } from 'validation-vue'

const app = createApp(App)
app.component('VForm', VForm)
app.component('VInput', VInput)
app.component('VSelect', VSelect)

app.mount('#app')

Form Events

The <VForm> component emits the following event:

  • @submitForm: Emitted when the form is submitted and the form valid.
  • @submitFailed: Emitted when the form is submitted and the form is not valid.
  • @submitStart: Emitted when start form submition. This event can be used to trigger actions such as showing a loading indicator or disabling the form during submission.

Properties

Shared Properties

| Property | Type | Default | Description | | ------------------ | ---------- | -------------- | ---------------------------------------------- | | id | String | required | The unique identifier for the component. | | required | Boolean | false | Indicates whether the input / select is required. | | primaryColor | String | '#005FAA' | The primary color for the field. For example, you can use this color to change the color of the show-password icon. | | errorColor | String | '#c10015' | The color to indicate an error state in the component. |

Input Properties

Properties define the behavior of the v-input component:

| Property | Type | Default | Description | | ------------------ | ---------- | -------------- | ----------------------------------------------------------- | | type | String | 'text' | The type of input. | | placeholder | String | '' | The placeholder text for the input. | | label | String | '' | The label text for the input. | | readonly | Boolean | false | Readonly input | | preventFocus | Boolean | false | Indicates whether to prevent focus in readonly mode | | focus | Boolean | false | When changing 'focus' to true the input is focused | | autofocus | Boolean | false | Indicates whether the input is focused when mounted | | rules | Array | [] | The rules prop is an array of validation rules that can be applied to the input or select component. It allows you to specify various validation conditions to validate the entered value. The rules can be defined either as strings or as pointers to validation functions from the parent element. When using strings, you can provide names of pre-defined validation options such as 'required', 'email', 'cc', 'minLength:6', 'maxLength:10' etc. These validation options represent common validation rules that can be applied to the input. Alternatively, you can define custom validation rules using pointers to validation functions from the parent element. Each validation function should take the value as a parameter and return an object with two properties: isValid and errorMessage. isValid indicates whether the value passes the validation condition, and errorMessage provides the error message to display when the validation fails. Here's an example: rules: [(value) => ({ isValid: /[A-Z]/.test(value), errorMessage: 'Password must contain at least 1 uppercase character' })] | | asyncRule | Function | null | A pointer to an asynchronous validation function. Please refer to Async Example below for an illustration of the asyncRule usage. | | submitRule | Function | null | A pointer to an asynchronous validation function. Run a specific check on the data, but only when submitting the form. By default, after the first submission, it will continue to check on input. | | validateOnSubmitOnly | Boolean | false | If there is a submit rule defined and you want the validation to occur only when submitting the form, set this prop to true. This will ensure that the submit rule is checked for validation only during form submission, even after the first submission. | | showValidIcon | Boolean | false | Indicates whether to show a valid icon. | | showPasswordIcon | Boolean | false | Indicates whether to show a password icon. | | required | Boolean | false | Indicates whether the input is required. | | isChecklist | Boolean | false | Indicates whether the input has a checklist of validations. | | isChecklistGrid | Boolean | true | Indicates whether to use a grid layout for checklist items. | | hideAsterisk | Boolean | false | Indicates whether a red asterisk (*) should not be displayed next to the label as a visual indicator of a required field. (By default the asterisk is shown). | | isDigitsOnly | Boolean | false | Indicates whether the input should accept only digits. | | maxLength | Number | Infinity | The maximum number of characters allowed in the input. | | minLength | Number | 0 | The minimum number of characters required in the input. | | textareaRows | Number | 0 | The number of rows for a textarea input. | | errorColor | String | '#c10015' | The color of the error message and error icon. | | validColor | String | '#7CB261' | The color of the success icon. | | placeholderColor | String | '#7B97AC' | The color of the placeholder text. |

Select Properties

Properties define the behavior of the v-select component:

| Property | Type | Default | Description | | ------------------ | ---------- | -------------- | -------------| | options | Array | [] | An array of options for the Select component. The options can either be primitive values (e.g. [1,2,3] or ['USA', 'Canada', 'Israel']) or objects with { label: '', key: '' } structure. | | iconColor | String | '#005FAA' | The color of the arrow icon. | | bgColor | String | '#fff' | The backgroung color of the select. | | selectLabel | String | '' | The label for the select component. | | isInsideLabel | Boolean | false | Determines if the label should be inside the select box. | | defaultOption | Object | { label: 'Choose', key: '' } | The default option for the select component. | | isSearch | Boolean | false | Determines if a search functionality should be enabled. |

Examples

Form example GIF

Async Example

<template>
  <VInput :idx="0" id="input" v-model="name" :asyncRule="validateAsync"/>
</template>
<script>
import { VInput } from 'validation-vue'
export default {
  data() {
      return {
          name: '',
      }
  },
  methods: {
  validateAsync(val) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve({
            isValid: val.includes('123'),
            errorMessage: 'Username must include 123',
          })
      }, 2000)
    })
  },
},
  components: { VInput }
}
</script>

Contribution

Contributions to the Validation-Vue package are welcome! If you find any issues or have suggestions for improvement, please open an issue on the GitHub repository or submit a pull request.

This task will create a distribution version of the project inside your local dist/ folder

Authors

License

MIT License © Dvir Cohen