custom-validator-directive

AngulaJS custom validator directive


Keywords
angularJS, custom, validator, directive
License
MIT
Install
bower install custom-validator-directive#v1.0.0

Documentation

AngularJS custom validator directive

license

Useful links

Requirements

  • Validation must happen inside <form> tag
  • Input must have ng-model specified for it

Supported attributes

  • dt-custom: Function that returns promise
  • error-field: Field name that will be in $error object, default is 'custom'

Installation Methods

npm

$ npm install custom-validator-directive

bower

$ bower install custom-validator-directive

Add Dependency

// Regular angularjs
// First of all add script `../custom-validator-directive/dist/custom-validator-directive.min.js` to your `index.html` file
// And then add it as module dependency
angular.module('myApp', ['dev-team-custom-validator', ...])

// requirejs
define(['angular', 'dev-team-custom-validator'], function(angular) {...});

// commonjs
var angular = require('angular');
angular.module('app', [require('dev-team-custom-validator'), ....])

How to use

In HTML:

<input type="text" name="field" dt-custom="validationFunction(t)" error-field="customErrorName" ng-model="ctrl.customField"/>

<div>{{form.field.$error.customErrorName}}</div>

validationFunction should be like this:

function() {
    var deferred = $q.defer();

    //some async logic, and then:
    deferred.resolve({
        IsValid: false // or true
    });

    return deferred.promise;
}

Feedback

Please leave your feedback if you have noticed any issues or have a feature request.

License

The repository code is open-sourced software licensed under the MIT license.