diff --git a/.travis.yml b/.travis.yml index 6bca260..b066bcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ +sudo: false # use container-based virtualization environment language: node_js node_js: - - "0.10" - - "0.11" + - "6" # Node.js LTS maintained until April 2019, https://github.com/nodejs/lts + - "node" # latest stable Node.js release before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start - 'npm install -g bower grunt-cli' - - 'bower install --config.interactive=false' \ No newline at end of file + - 'bower install --config.interactive=false' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 266a13f..47319b4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,13 +6,12 @@ Thanks for wanting to contribute. Please follow the instructions below. 1. Clone the repository 2. Run `bower install` in the repository directory 3. Run `npm install` in the repository directory -4. Run `grunt serve` to start servering the demo on `http://localhost:9001/demo/` - +4. Run `grunt serve` to start serving the demo on `http://localhost:9001/demo/` ## Before creating a pull request 1. Make sure you add tests to `/test/angular-validator-spec.js` that test your changes. To run tests `grunt test` -2. If approriate update the readme to reflect your changes. +2. If appropriate update the README to reflect your changes. 3. Run `grunt build` to minify and create a `dist` version of your changes -4. If approriate update the demo in /demo/ +4. If appropriate update the demo in /demo/ 5. The project maintainer will update the Plunker demo that is linked in README.md if needed. \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 9f4cbc4..0b7eacb 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,3 +1,8 @@ +/*jslint node: true */ +'use strict'; + +var pkg = require('./package.json'); + module.exports = function(grunt) { // Grunt Config @@ -21,6 +26,12 @@ module.exports = function(grunt) { "dest": "dist/angular-validator.js" } }, + ngAnnotate: { + main: { + src: 'dist/angular-validator.js', + dest: 'dist/angular-validator.js' + }, + }, uglify: { dist: { src: "dist/angular-validator.js", @@ -66,6 +77,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-connect'); + grunt.loadNpmTasks('grunt-ng-annotate'); // Load the plugin that provides the "jshint" task. grunt.loadNpmTasks('grunt-contrib-jshint'); @@ -81,8 +93,8 @@ module.exports = function(grunt) { // Register Task grunt.registerTask('serve', ['connect', 'watch']); - grunt.registerTask('build', ['concat', 'uglify', 'karma:build',]); - grunt.registerTask('test', ['karma:build',]); + grunt.registerTask('build', ['concat', 'ngAnnotate', 'uglify', 'karma:build']); + grunt.registerTask('test', ['karma:build', ]); grunt.registerTask('test-debug', ['karma:debug']); grunt.registerTask('travis', ['karma:travis']); }; \ No newline at end of file diff --git a/README.md b/README.md index 1a552d7..34d6850 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,31 @@ # Angular-Validator [](https://travis-ci.org/turinggroup/angular-validator) - -## What? Angular-Validator is an easy to use, powerful and lightweight AngularJS validation directive. - -## Why? -Despite Angular's awesomeness, validation in Angular is still a pain in the ass. 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. - +## Demo +[Check out the demo!](http://plnkr.co/edit/XbDYKrM2QUf8g1ubTHma?p=preview) ## Features -* Validate using REGEX, required, or custom validation functions -* Validates elements on submit with option to validate individual elements on `blur` or `dirty` as well. +* Validate using regex, HTML5, or custom validation functions. +* Works seamlessly with all native AngularJS validation directives and native HTML5 validation attributes. +* Supports custom validation message templates and placement using Angular's native `ngMessages` directive. +* Choose when to validate elements, on per-element basis. Choose between on form `submission`, `blur` or `dirty`(change). +* All validation states and validation messages are accessible through `$scope.yourFormName.elementName`. * Prevents submission if the form is invalid -* Built in reset form method -* Adds validation error/success messages as sibling elements -* Adds `.has-error` classes to invalid elements -* Adds `.has-error` classes to validation message +* Built in `reset()` form method * Supports multi-field dependent validation (one field depends on another such as password matching) -* Works with or without `novalidate` * Works with Bootstrap out of the box (although Bootstrap is not required) +* Optionally adds `.has-error` classes to invalid form and message message elements so you don't have to. +* Supports form invalid message service where manage invalid messages in one place and save code in HTML - -## Demo -[Check out the demo!](http://plnkr.co/edit/XbDYKrM2QUf8g1ubTHma?p=preview) - - -## Feedback -Need a feature, found a bug? Create an issue. Dont have any issues, love the project? Give it a star! +## Why? +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. ## Installation -1. Using bower: `bower install tg-angular-validator` -2. Include `angular-validator.min.js` into your application's HTML -3. Add `angularValidator` as a dependancy of your Angular module +1. Using bower: `bower install tg-angular-validator`. +2. Include `angular-validator.min.js`. +3. Add `angularValidator` as a dependency of your Angular module. ## Usage @@ -50,7 +42,7 @@ Need a feature, found a bug? Create an issue. Dont have any issues, love the pro + validator = "myValidationFunction(person.firstName)"> ``` **Usage with validation on blur** @@ -59,7 +51,7 @@ Need a feature, found a bug? Create an issue. Dont have any issues, love the pro name = "firstName" ng-model = "person.firstName" validate-on="blur" - validator = "myCustomValidationFunction(form.firstName)"> + validator = "myValidationFunction(person.firstName)"> ``` **Usage with validation on dirty** @@ -68,7 +60,7 @@ Need a feature, found a bug? Create an issue. Dont have any issues, love the pro name = "firstName" ng-model = "person.firstName" validate-on="dirty" - validator = "myCustomValidationFunction(form.firstName)"> + validator = "myValidationFunction(person.firstName)"> ``` **Usage with custom validator literal** @@ -76,7 +68,7 @@ Need a feature, found a bug? Create an issue. Dont have any issues, love the pro + validator = "person.firstname === 'john'"> ``` **Usage with REGEX and required** @@ -84,7 +76,7 @@ Need a feature, found a bug? Create an issue. Dont have any issues, love the pro ``` @@ -93,7 +85,7 @@ Need a feature, found a bug? Create an issue. Dont have any issues, love the pro @@ -104,37 +96,71 @@ Need a feature, found a bug? Create an issue. Dont have any issues, love the pro ``` * 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. +**Usage without auto-generated error label** + +``` + +``` + +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. + **Setting up the form** ``` -
``` 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. + +**Use form invalid message service** +``` + +``` +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. + +**Usage form without auto-generated error label** + +``` +