diff --git a/README.md b/README.md index ce198c2..456ece6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# Angular-Validator +This is just a fork of https://github.com/turinggroup/angular-validator with Asynchronous Validator, please see demo for example. + +# Angular-Validator [![Build Status](https://travis-ci.org/turinggroup/angular-validator.png)](https://travis-ci.org/turinggroup/angular-validator) Angular-Validator is an easy to use, powerful and lightweight AngularJS validation directive. @@ -11,7 +13,7 @@ Angular-Validator is an easy to use, powerful and lightweight AngularJS validati * 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`. +* All validation states and validation messages are accessible through `$scope.yourFormName.elementName`. * Prevents submission if the form is invalid * Built in `reset()` form method * Supports multi-field dependent validation (one field depends on another such as password matching) @@ -20,7 +22,7 @@ Angular-Validator is an easy to use, powerful and lightweight AngularJS validati * Supports form invalid message service where manage invalid messages in one place and save code in HTML ## 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. +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`. @@ -80,6 +82,20 @@ Despite Angular's awesomeness, validation in Angular is still annoying. Surprisi required> ``` +**Usage with asynchronous validator** + +``` + +``` + +* validator-async requires the callback function to return promise to make it work. see [angular's ngModel.$asyncValidators](https://docs.angularjs.org/api/ng/type/ngModel.NgModelController) for how to use it. + **Usage with custom error message text** ``` Different types of validation: validate-on="dirty" required> +
+ +
+
+
@@ -188,8 +199,8 @@

Scope Sneak Peak

Form submitted: {{myForm.submitted}}

- + - \ No newline at end of file + diff --git a/demo/service/john.json b/demo/service/john.json new file mode 100644 index 0000000..ac855fe --- /dev/null +++ b/demo/service/john.json @@ -0,0 +1,5 @@ +{ + "username": "john", + "first_name": "John", + "last_name": "Doe" +} diff --git a/dist/angular-validator.js b/dist/angular-validator.js index 5838d66..1b7051d 100644 --- a/dist/angular-validator.js +++ b/dist/angular-validator.js @@ -5,6 +5,37 @@ angular.module('angularValidator').directive('angularValidator', ['$injector', ' return { restrict: 'A', link: function(scope, element, attrs, fn) { + var getRandomInt = function() { + return Math.floor((Math.random() * 100000)); + }; + + // For this directive to work the form needs a name attribute as well as every input element. + // This function will add names where missing + var need_to_recompile = false; + + // Iterate through all the children of the form element and add a `name` attribute to the ones + // that are missing it. + angular.forEach(element.find('input,select,textarea'), function(child_element) { + child_element = $(child_element); + if (!child_element.attr('name')) { + child_element.attr('name', getRandomInt()); + console.log('WARNING! AngularValidator -> One of your form elements(,