Coder Social home page Coder Social logo

ncform-gtn-validators's Introduction

This library provides additional validation rules for ncform

Installation

npm i ncform-gtn-validators

Usage

To add this library to ncform just register rules


import rules from 'ncform-gtn-validators'
Vue.use(vueNcform, { extRules: rules });

Describe validation options in rule section of property

    rules: {
        snils: {
            value: true,
            errMsg: "validation error"
        }
    }

Features

At this momments library provides validators for БИК(bik), ИНН(inn), СНИЛС(snils), КПП(kpp), Корр.счет(ks), ОГРН(ogrn), ОГРНИП(ogrnip)

Contribution

  1. Copy this repositorty
  2. Create new branch
  3. Extend ValidationRule class
# myCustomRule.js

import ncformCommon from '@ncform/ncform-common';

class MyCustomRule extends ncformCommon.ValidationRule {

  constructor(props) {
    super(props);
    this.name = 'myCustom'; // your rule name
    this.defaultErrMsg = 'yeah, show my custom rule message'; // you rule default error message tips
  }

  validateLogic(val, ruleVal) {
    // val: the input value for validating
    // ruleVal: rule's value. example: {maxLength: {value: 1}}, the ruleVal's value here is 1  
    // You can change the error message programmatically by setting this.errMsg. (e.g. this.errMsg = 'There are some errors')
    // You can use this.$http to make some http request (this.$http is the same as axios)
    return true;
    // or return new Promise(resolve => resolve(true))
  }

}

export default MyCustomRule;
  1. Add new class to rules array in index.js
    const extRules = [
        {inn: innValidator},
        {snils: snilsValidator},
        {custom: MyCustomRule} // like that
    ]
  1. Create pull request

ncform-gtn-validators's People

Contributors

arsenitem avatar wwwokeisha avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.