Coder Social home page Coder Social logo

col128 / angular-validation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hueitan/angular-validation

0.0 2.0 0.0 1.62 MB

Client Side Validation for AngularJS - http://huei90.github.io/angular-validation/

JavaScript 98.84% CSS 0.10% HTML 1.06%

angular-validation's Introduction

angular-validation 1.4.2

NPM version Build Status Code Climate Coverage Status devDependency Status Gitter chat

Client-side Validation should be simple and clean.
Don't let Client-side Validation dirty your controller.

Setup your Validation on config phase by using some rules (example)
If you prefer schema over html attributes , try angular-validation-schema (Demo)
And add Validation in your view only.

angularjs 1.2.x support to version angular-validation 1.2.x
angularjs 1.3.x support after version angular-validation 1.3.x
angularjs 1.4.x support after version angular-validation 1.4.x

Requirement

AngularJS 1.2.x (for angular-validation 1.2.x)
AngularJS 1.3.x (for angular-validation 1.3.x)
AngularJS 1.4.x (for angular-validation 1.4.x)

DEMO

http://huei90.github.io/angular-validation/

http://plnkr.co/edit/rjIIkX (Bootstrap framework)

Install

Install with npm

npm install angular-validation

or with bower

bower install angular-validation

Using angular-validation

<script src="dist/angular-validation.js"></script>
<script src="dist/angular-validation-rule.js"></script>
angular.module('yourApp', ['validation']);

// OR including your validation rule
angular.module('yourApp', ['validation', 'validation.rule']);

Writing your First Code

<form name="Form">
    <div class="row">
        <div>
            <label>Required</label>
            <input type="text" name="required" ng-model="form.required" validator="required">
        </div>
        <div>
            <label>Url</label>
            <input type="text" name="url" ng-model="form.url" validator="required, url">
        </div>
        <button validation-submit="Form" ng-click="next()">Submit</button>
        <button validation-reset="Form">Reset</button>
    </div>
</form>

Documentation API

Built-in validation in angular-validation-rule

  1. Required
  2. Url
  3. Email
  4. Number
  5. Min length
  6. Max length

5 and 6 require you to pass an inline parameter to set the length limit. Eg, maxlength=6.

Anyone can give a PR for this angular-validation for more built-in validation

Integrating with Twitter Bootstrap

To integrate this package with Bootstrap you should do the following.

Add the following LESS to your project

.ng-invalid.ng-dirty{
    .has-error .form-control;
}

label.has-error.control-label {
    .has-error .control-label;
}

Change the Error HTML to something like:

$validationProvider.setErrorHTML(function (msg) {
       return  "<label class=\"control-label has-error\">" + msg + "</label>";
});

You can add the bootstrap class .has-success in a similar fashion.

To toggle .has-error class on bootstrap .form-group wrapper for labels and controls, add:

angular.extend($validationProvider, {
    validCallback: function (element){
        $(element).parents('.form-group:first').removeClass('has-error');
    },
    invalidCallback: function (element) {
        $(element).parents('.form-group:first').addClass('has-error');
    }
});

License

MIT

CHANGELOG

See release

CONTRIBUTORS

Thanks for all contributors

angular-validation's People

Contributors

a15n avatar arthurhenning avatar austinpray avatar ctjhoa-linagora avatar dizlexik avatar dmitry-dedukhin avatar dvelopment avatar eyupatis avatar hueitan avatar huguangju avatar hung-doan avatar imgarylai avatar imranamans avatar lopsided avatar lvarayut avatar musahaidari avatar nazanin1369 avatar nmccready avatar null-none avatar tb avatar thetutlage avatar think2011 avatar tylergraf avatar zack9433 avatar

Watchers

 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.