├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── Gruntfile.js ├── README.md ├── bower.json ├── demo ├── app.js └── index.html ├── dist ├── angular-validator.js └── angular-validator.min.js ├── karma.conf.js ├── package.json ├── src └── angular-validator.js └── test └── angular-validator-spec.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bower_components 3 | npm-debug.log -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false # use container-based virtualization environment 2 | language: node_js 3 | node_js: 4 | - "6" # Node.js LTS maintained until April 2019, https://github.com/nodejs/lts 5 | - "node" # latest stable Node.js release 6 | before_script: 7 | - export DISPLAY=:99.0 8 | - sh -e /etc/init.d/xvfb start 9 | - 'npm install -g bower grunt-cli' 10 | - 'bower install --config.interactive=false' 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | Thanks for wanting to contribute. Please follow the instructions below. 3 | 4 | 5 | ## Getting started 6 | 1. Clone the repository 7 | 2. Run `bower install` in the repository directory 8 | 3. Run `npm install` in the repository directory 9 | 4. Run `grunt serve` to start serving the demo on `http://localhost:9001/demo/` 10 | 11 | 12 | ## Before creating a pull request 13 | 1. Make sure you add tests to `/test/angular-validator-spec.js` that test your changes. To run tests `grunt test` 14 | 2. If appropriate update the README to reflect your changes. 15 | 3. Run `grunt build` to minify and create a `dist` version of your changes 16 | 4. If appropriate update the demo in /demo/ 17 | 5. The project maintainer will update the Plunker demo that is linked in README.md if needed. -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /*jslint node: true */ 2 | 'use strict'; 3 | 4 | var pkg = require('./package.json'); 5 | 6 | module.exports = function(grunt) { 7 | 8 | // Grunt Config 9 | grunt.initConfig({ 10 | pkg: grunt.file.readJSON('package.json'), 11 | 12 | connect: { 13 | server: { 14 | options: { 15 | port: 9001, 16 | base: '.' 17 | } 18 | } 19 | }, 20 | concat: { 21 | "options": { 22 | "separator": ";" 23 | }, 24 | "build": { 25 | "src": "src/*.js", 26 | "dest": "dist/angular-validator.js" 27 | } 28 | }, 29 | ngAnnotate: { 30 | main: { 31 | src: 'dist/angular-validator.js', 32 | dest: 'dist/angular-validator.js' 33 | }, 34 | }, 35 | uglify: { 36 | dist: { 37 | src: "dist/angular-validator.js", 38 | dest: "dist/angular-validator.min.js" 39 | } 40 | }, 41 | jshint: { 42 | files: ['Gruntfile.js', 'src/*.js'], 43 | options: { 44 | jshintrc: true 45 | } 46 | }, 47 | watch: { 48 | files: ['src/*.js', 'demo/*.*'], 49 | tasks: ['build'], 50 | options: { 51 | livereload: true 52 | } 53 | }, 54 | karma: { 55 | options: { 56 | configFile: 'karma.conf.js' 57 | }, 58 | build: { 59 | singleRun: true, 60 | autoWatch: true 61 | }, 62 | debug: { 63 | singleRun: false, 64 | autoWatch: true, 65 | browsers: ['Chrome'] 66 | }, 67 | travis: { 68 | singleRun: true, 69 | autoWatch: false, 70 | browsers: ['Firefox'] 71 | }, 72 | dev: { 73 | autoWatch: true 74 | } 75 | } 76 | }); 77 | 78 | grunt.loadNpmTasks('grunt-contrib-watch'); 79 | grunt.loadNpmTasks('grunt-contrib-connect'); 80 | grunt.loadNpmTasks('grunt-ng-annotate'); 81 | 82 | // Load the plugin that provides the "jshint" task. 83 | grunt.loadNpmTasks('grunt-contrib-jshint'); 84 | 85 | // Load the plugin that provides the "concat" task. 86 | grunt.loadNpmTasks('grunt-contrib-concat'); 87 | 88 | // Load the plugin that provides the "uglify" task. 89 | grunt.loadNpmTasks('grunt-contrib-uglify'); 90 | grunt.loadNpmTasks('grunt-karma'); 91 | 92 | 93 | 94 | // Register Task 95 | grunt.registerTask('serve', ['connect', 'watch']); 96 | grunt.registerTask('build', ['concat', 'ngAnnotate', 'uglify', 'karma:build']); 97 | grunt.registerTask('test', ['karma:build', ]); 98 | grunt.registerTask('test-debug', ['karma:debug']); 99 | grunt.registerTask('travis', ['karma:travis']); 100 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Angular-Validator 2 | [](https://travis-ci.org/turinggroup/angular-validator) 3 | 4 | Angular-Validator is an easy to use, powerful and lightweight AngularJS validation directive. 5 | 6 | ## Demo 7 | [Check out the demo!](http://plnkr.co/edit/XbDYKrM2QUf8g1ubTHma?p=preview) 8 | 9 | ## Features 10 | * Validate using regex, HTML5, or custom validation functions. 11 | * Works seamlessly with all native AngularJS validation directives and native HTML5 validation attributes. 12 | * Supports custom validation message templates and placement using Angular's native `ngMessages` directive. 13 | * Choose when to validate elements, on per-element basis. Choose between on form `submission`, `blur` or `dirty`(change). 14 | * All validation states and validation messages are accessible through `$scope.yourFormName.elementName`. 15 | * Prevents submission if the form is invalid 16 | * Built in `reset()` form method 17 | * Supports multi-field dependent validation (one field depends on another such as password matching) 18 | * Works with Bootstrap out of the box (although Bootstrap is not required) 19 | * Optionally adds `.has-error` classes to invalid form and message message elements so you don't have to. 20 | * Supports form invalid message service where manage invalid messages in one place and save code in HTML 21 | 22 | ## Why? 23 | Despite Angular's awesomeness, validation in Angular is still annoying. Surprisingly there are no seamless, user-friendly, well written Angular validation tools. Unlike other Angular validation tools, Angular-Validator works with out-of-the-box Angular and HTML5 validation, directives and attributes, allowing your forms to work well with the browser and other Javascript code. 24 | 25 | ## Installation 26 | 1. Using bower: `bower install tg-angular-validator`. 27 | 2. Include `angular-validator.min.js`. 28 | 3. Add `angularValidator` as a dependency of your Angular module. 29 | 30 | ## Usage 31 | 32 | **Basic usage for required fields** 33 | ``` 34 | 38 | ``` 39 | 40 | **Usage with a custom validator function** 41 | ``` 42 | 46 | ``` 47 | 48 | **Usage with validation on blur** 49 | ``` 50 | 55 | ``` 56 | 57 | **Usage with validation on dirty** 58 | ``` 59 | 64 | ``` 65 | 66 | **Usage with custom validator literal** 67 | ``` 68 | 72 | ``` 73 | 74 | **Usage with REGEX and required** 75 | ``` 76 | 81 | ``` 82 | 83 | **Usage with custom error message text** 84 | ``` 85 | 92 | ``` 93 | 94 | **Usage with conditional invalid/required message text** 95 | ``` 96 | 103 | ``` 104 | * Note that the validator and the message function do not need to be the same function. If you choose to make them the same function make sure to return `true` on valid input. 105 | 106 | **Usage without auto-generated error label** 107 | 108 | ``` 109 | 115 | ``` 116 | 117 | Use `angular-validator-quiet` on an element to prevent the auto-generation of new DOM element `label` after this inputs. You then have complete control over the location and classes used to show the error messages. 118 | 119 | **Setting up the form** 120 | ``` 121 |
126 | ``` 127 | Use `angular-validator-submit` to specify the function to be called when the form is submitted. Note that the function is not called if the form is invalid. 128 | 129 | 130 | **Use form invalid message service** 131 | ``` 132 | 138 | ``` 139 | Use `invalid-message` on form element to provide the name of the service in which invalid messages are managed. You need to provide a `message` function in your service, which returns the messages you defined. Form invalid message service saves repetitive code in HTML because you do not need to use invalid-message attribute on every field. Please see the demo for examples. 140 | 141 | **Usage form without auto-generated error label** 142 | 143 | ``` 144 |