New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-validate-directive

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-validate-directive

simple AngularJS validation directive

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-37.5%
Maintainers
1
Weekly downloads
 
Created
Source

angular-validate-directive

An angular directive for doing one-off custom validation.

Under the hood this directive uses the validator API introduced in angular 1.3. See NgModelController's $validators and $asyncValidators properties:

https://docs.angularjs.org/api/ng/type/ngModel.NgModelController

Usage

  1. Include validate.js on your page after angular.js
  2. Add dbrans.validate as a dependency of your app.

Synchronous validation

<form name="myForm">
  <input name="foo" ng-model="foo" dbrans-validate="{odd: isOdd}">
  <div ng-messages="myForm.foo.$error">
    <div ng-message="odd">You need to pick an odd number.</div>
  </div>
</form>
angular.module('yourModule')
  .controller('MyController', function($scope) {
    $scope.isOdd = function(x) { return x % 2 === 1; };
});

Async validation

<form name="myForm">
  Choose a unique username: 
  <input name="username" ng-model="username" 
         dbrans-validate-async="{unique: isUsernameUnique}">
  <div ng-messages="myForm.username.$error">
    <div ng-message="unique">Sorry, that username is taken.</div>
  </div>
</form>
angular.module('yourModule')
  .controller('MyController', function($scope, $http, $q) {
    $scope.isUsernameUnique = function(username) { 
      $http.get('/api/user/' + username).then(function() {
        return $q.reject(); // 200 - user exists
      }, function() {
        return true; // 404 - user does not exist
      });
    };
});

Keywords

FAQs

Package last updated on 04 Nov 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc