[
  {
    "path": ".bowerrc",
    "content": "{\n  \"directory\": \"bower_components\"\n}"
  },
  {
    "path": ".editorconfig",
    "content": "root = true\n\n[*]\nindent_style = space\nindent_size = 2\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\n"
  },
  {
    "path": ".gitignore",
    "content": ".DS_Store\nnode_modules\nbower_components\ndist\ncoverage\ndemo/js\nnpm-debug.log\n*.iml\n.idea/\n"
  },
  {
    "path": ".jshintrc",
    "content": "{\n  \"predef\": [\n    \"describe\",\n    \"it\",\n    \"xit\",\n    \"expect\",\n    \"angular\",\n    \"beforeEach\",\n    \"spyOn\",\n    \"inject\",\n    \"module\",\n    \"xdescribe\",\n    \"ddescribe\",\n    \"moment\",\n    \"jasmine\"\n  ],\n  \"esnext\": false,\n  \"bitwise\": true,\n  \"curly\": true,\n  \"eqeqeq\": true,\n  \"immed\": true,\n  \"indent\": 2,\n  \"latedef\": false,\n  \"newcap\": true,\n  \"noarg\": true,\n  \"quotmark\": \"single\",\n  \"undef\": true,\n  \"unused\": true,\n  \"strict\": false,\n  \"trailing\": true,\n  \"smarttabs\": true,\n  \"browser\": true,\n  \"node\": true\n}\n"
  },
  {
    "path": ".travis.yml",
    "content": "language: node_js\nnode_js:\n  - \"0.10\"\n\nbefore_install:\n  - npm install -g grunt-cli karma-cli bower\n\nbefore_script:\n  - export DISPLAY=:99.0\n  - sh -e /etc/init.d/xvfb start\n\nscript: grunt"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n## 1.1.6 - 2016-09-14\n- Fix: min length validator and size validator validate only length [#107](https://github.com/netceteragroup/valdr/pull/107)\n- Fix: Fixed memory leak in valdrMessage-directive [#105](https://github.com/netceteragroup/valdr/pull/105)\n- Fix: Unable to validate multiselect dropdowns [#101](https://github.com/netceteragroup/valdr/issues/101)\n\n## 1.1.5 - 2015-09-22\n- Don't throw exception if an input has no name and valdr is disabled [#92](https://github.com/netceteragroup/valdr/pull/92)\n\n## 1.1.4 - 2015-08-11\n- Fix: valdrMessage does not add messages of angular validation directives [#90](https://github.com/netceteragroup/valdr/issues/90)\n\n## 1.1.3 - 2015-06-22\n- Support to validate non-input/-select/-textarea widgets [#83](https://github.com/netceteragroup/valdr/issues/83) [documentation](https://github.com/netceteragroup/valdr#applying-validation-to-custom-input-widgets)\n\n## 1.1.2 - 2015-05-03\n- Support dynamically added and removed form items, see [#62](https://github.com/netceteragroup/valdr/issues/62)\n- Support showing validation messages for AngularJS built-in validators, see [#58](https://github.com/netceteragroup/valdr/issues/58)\n\n## 1.1.1 - 2015-01-04\n- introduce ```valdrEnabled``` directive to conditionally enable/disable validation, see [#54](https://github.com/netceteragroup/valdr/issues/54)\n- fix bug that after removing constraints from valdr with valdr.removeConstraints(), the validity state of previously validated form items was not reset. see [#55](https://github.com/netceteragroup/valdr/issues/55)\n\n## 1.1.0 - 2014-12-09\n- added new valdrFormGroup directive which sets validity state for a group of form items and is responsible for adding and removing validation messages if valdr-message is loaded, see [#11](https://github.com/netceteragroup/valdr/issues/11), fixes [#44](https://github.com/netceteragroup/valdr/issues/44), fixes [#48](https://github.com/netceteragroup/valdr/issues/48)\n- support multiple aliases for constraint names, see [#30](https://github.com/netceteragroup/valdr/issues/30)\n- use the latest regular expression to validate e-mail addresses used in AngularJS, see [#33](https://github.com/netceteragroup/valdr/issues/33)\n- use new $validators pipeline from AngularJS 1.3 instead of $parsers and $formatters for validation, see [#35](https://github.com/netceteragroup/valdr/issues/35)\n- renamed no-valdr-message to valdr-no-message, see [#42](https://github.com/netceteragroup/valdr/issues/42)\n- use ng-show in the default message template instead of ng-if, fixes [#49](https://github.com/netceteragroup/valdr/issues/49)\n\n**BREAKING CHANGES**\n- valdr now requires AngularJS 1.3.x.\n- Before 1.1.0 a class named ```form-group``` was used to group multiple form items and add overall validity state. In 1.1.0\nthe new directive ```valdr-form-group``` was introduced for this purpose. All valdr validated form fields register with\nthe next parent element with the ```valdr-form-group```directive (if present). The directive sets the form groups validity\n(```ng-valid```, ```ng-invalid```) and the class ```valdr-invalid-dirty-touched-group``` if one of the form items is\ninvalid, has been changed and the user blurred out of the form item. Besides that, if ```valdr-messages```\nis used to add validation messages, the ```valdr-form-group``` directive is the element in the DOM which adds and\nremoves validation messages for all form items in the group.\n- the attribute ```no-valdr-message``` was renamed to ```valdr-no-message``` to disable message adding for individual\nform items\n\n## 1.0.2 - 2014-11-18\n- added new option ```valdr-no-validate``` to disable valdr validation on specific form elements, see [#41](https://github.com/netceteragroup/valdr/pull/41)\n- validity is now set for each valdr validator on ngModel controller, see [#37](https://github.com/netceteragroup/valdr/issues/37)\n- NOTE: this will be the last valdr version with support for AngularJS versions below 1.3\n\n## 1.0.1 - 2014-07-16\n- Revalidate field with $modelValue instead of $viewValue on constraint change event, fixes [#34](https://github.com/netceteragroup/valdr/pull/34)\n\n## 1.0.0 - 2014-06-27\n- added support for isolated scopes around valdr-message directive, closes [#32](https://github.com/netceteragroup/valdr/issues/32)\n\n## 0.2.0 - 2014-05-03\n- add hibernateEmail validator, closes [#26](https://github.com/netceteragroup/valdr/issues/26)\n- add hibernateUrl validator, closes [#27](https://github.com/netceteragroup/valdr/issues/27)\n- add support for <textarea> elements, closes [#22](https://github.com/netceteragroup/valdr/issues/22)\n- support form groups with multiple levels, closes [#29](https://github.com/netceteragroup/valdr/issues/29)\n- add min/max validators for numbers\n- prefixed all internal validator services with valdr to avoid name collisions\n\n## 0.1.1 - 2014-04-17\n- add support for <select> elements, closes [#20](https://github.com/netceteragroup/valdr/issues/20)\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# Contributing Guide\n\n\n## Commit messages\n\nFollow the [AngularJS conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit).\n"
  },
  {
    "path": "Gruntfile.js",
    "content": "'use strict';\n\nmodule.exports = function (grunt) {\n\n  require('load-grunt-tasks')(grunt);\n\n  grunt.initConfig({\n\n    pkg: grunt.file.readJSON('package.json'),\n\n    language: grunt.option('lang') || 'en',\n\n    meta: {\n      banner: '/**\\n * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +\n      '<%= grunt.template.today(\"yyyy-mm-dd\") %>\\n' +\n      ' * <%= pkg.homepage %>\\n' +\n      ' * Copyright (c) <%= grunt.template.today(\"yyyy\") %> <%= pkg.author.name %>\\n' +\n      ' * License: <%= pkg.license %>\\n */\\n'\n    },\n\n    build_dir: 'dist',\n\n    files: {\n\n      core: [\n        'src/valdr.js',\n        'src/core/valdrUtil-service.js',\n        'src/core/validators/requiredValidator.js',\n        'src/core/validators/minValidator.js',\n        'src/core/validators/maxValidator.js',\n        'src/core/validators/sizeValidator.js',\n        'src/core/validators/emailValidator.js',\n        'src/core/validators/urlValidator.js',\n        'src/core/validators/digitsValidator.js',\n        'src/core/validators/futureAndPastSharedValidator.js',\n        'src/core/validators/pastValidator.js',\n        'src/core/validators/futureValidator.js',\n        'src/core/validators/patternValidator.js',\n        'src/core/validators/minLengthValidator.js',\n        'src/core/validators/maxLengthValidator.js',\n        'src/core/validators/hibernateEmailValidator.js',\n        'src/core/valdr-service.js',\n        'src/core/valdrFormGroup-directive.js',\n        'src/core/valdrType-directive.js',\n        'src/core/valdrFormItem-directive.js',\n        'src/core/valdrEnabled-directive.js'\n      ],\n\n      message: [\n        'src/message/valdrMessage-service.js',\n        'src/message/valdrMessage-directive.js'\n      ],\n\n      test: ['src/**/*.spec.js']\n    },\n\n    jshint: {\n\n      options: {\n        jshintrc: true\n      },\n\n      all: ['Gruntfile.js', '<%= files.core %>', '<%= files.message %>', '<%= files.test %>'],\n\n      test: {\n        files: {\n          src: ['<%= files.test %>']\n        }\n      }\n    },\n\n    concat: {\n\n      banner: {\n        options: {\n          banner: '<%= meta.banner %>'\n        },\n        src: '<%= concat.core.dest %>',\n        dest: '<%= concat.core.dest %>'\n      },\n\n      core: {\n        src: ['js.prefix', '<%= files.core %>', 'js.suffix'],\n        dest: '<%= build_dir %>/valdr.js'\n      },\n\n      message: {\n        src: ['js.prefix', '<%= files.message %>', 'js.suffix'],\n        dest: '<%= build_dir %>/valdr-message.js'\n      }\n\n    },\n\n    uglify: {\n      core: {\n        files: {\n          '<%= build_dir %>/valdr.min.js': '<%= concat.core.dest %>'\n        }\n      },\n      message: {\n        files: {\n          '<%= build_dir %>/valdr-message.min.js': '<%= concat.message.dest %>'\n        }\n      }\n    },\n\n    karma: {\n      'unit': {\n        configFile: 'karma.conf.js',\n        singleRun: true,\n        browsers: ['PhantomJS']\n      },\n\n      'chrome-unit': {\n        configFile: 'karma.conf.js',\n        singleRun: true,\n        browsers: ['Chrome']\n      },\n\n      'firefox-unit': {\n        configFile: 'karma.conf.js',\n        singleRun: true,\n        browsers: ['Firefox']\n      }\n    },\n\n    copy: {\n\n      demo: {\n        files: [{\n          src: '*.js',\n          dest: 'demo/js/',\n          cwd: 'dist/',\n          expand: true\n        }]\n      }\n    },\n\n    watch: {\n      livereload: {\n        options: {\n          livereload: true\n        },\n        files: ['src/**/*.js'],\n        tasks: ['concat:core', 'concat:message', 'concat:banner', 'uglify:core', 'uglify:message', 'copy:demo']\n      }\n    },\n\n    express: {\n      server: {\n        options: {\n          port: 3005,\n          bases: '.',\n          server: __dirname + '/server.js'\n        }\n      }\n    }\n  });\n\n  grunt.registerTask('test', ['jshint:all', 'karma:unit']);\n  grunt.registerTask('default', ['test']);\n\n  // Advanced test tasks\n  grunt.registerTask('test-chrome', ['karma:chrome-unit']);\n  grunt.registerTask('test-firefox', ['karma:firefox-unit']);\n  grunt.registerTask('test-all', ['karma']);\n\n  grunt.registerTask('build', [\n    'jshint:all',\n    'karma:unit',\n    'concat:core',\n    'concat:message',\n    'concat:banner',\n    'uglify:core',\n    'uglify:message'\n  ]);\n\n  // For development purpose.\n  grunt.registerTask('dev', [\n    'build',\n    'copy:demo',\n    'watch:livereload'\n  ]);\n  grunt.registerTask('server', [\n    'express',\n    'express-keepalive'\n  ]);\n};\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2014 Netcetera AG\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# valdr\n[![Build Status](https://travis-ci.org/netceteragroup/valdr.svg?branch=master)](https://travis-ci.org/netceteragroup/valdr) [![Coverage Status](https://coveralls.io/repos/netceteragroup/valdr/badge.svg?branch=master)](https://coveralls.io/r/netceteragroup/valdr?branch=master) [![Code Climate](https://codeclimate.com/github/netceteragroup/valdr.svg)](https://codeclimate.com/github/netceteragroup/valdr) [![NPM version](https://badge.fury.io/js/valdr.svg)](http://badge.fury.io/js/valdr) [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/netceteragroup/valdr/blob/master/LICENSE) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/netceteragroup/valdr?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)\n\nA model centric approach to AngularJS form validation. Learn more on the [valdr website](http://netceteragroup.github.io/valdr/).\n\n<!-- START doctoc generated TOC please keep comment here to allow auto update -->\n<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->\n<!--**Table of Contents**  *generated with [DocToc](http://doctoc.herokuapp.com/)*-->\n\n  - [Why valdr](#why-valdr)\n  - [Install](#install)\n  - [Getting started](#getting-started)\n  - [Constraints JSON](#constraints-json)\n  - [Built-In Validators](#built-in-validators)\n    - [size](#size)\n    - [minLength / maxLength](#minlength--maxlength)\n    - [min / max](#min--max)\n    - [required](#required)\n    - [pattern](#pattern)\n    - [email](#email)\n    - [digits](#digits)\n    - [url](#url)\n    - [future / past](#future--past)\n  - [Adding custom validators](#adding-custom-validators)\n  - [Applying validation to custom input widgets](#applying-validation-to-custom-input-widgets)\n  - [Showing validation messages](#showing-validation-messages-with-valdr-messages)\n    - [Message template](#message-template)\n    - [CSS to control visibility](#css-to-control-visibility)\n    - [Integration of angular-translate](#integration-of-angular-translate)\n    - [Show messages for AngularJS built-in validators](#show-messages-for-angularjs-built-in-validators)\n  - [Conditionally enable/disable validation](#conditionally-enabledisable-validation)\n  - [Wire up your back-end](#wire-up-your-back-end)\n    - [Using JSR303 Bean Validation with Java back-ends](#using-jsr303-bean-validation-with-java-back-ends)\n    - [Using DataAnnotation with C# back-ends](#using-dataannotation-with-c-back-ends)\n  - [Develop](#develop)\n  - [Support](#support)\n  - [License](#license)\n  - [Credits](#credits)\n\n<!-- END doctoc generated TOC please keep comment here to allow auto update -->\n\n## Why valdr\nDefining the validation rules on every input field with the default AngularJS validators pollutes the markup with your\nbusiness rules and makes them pretty hard to maintain. This is especially true for larger applications, where you may\nhave recurring models like persons or addresses in different forms, but require slightly different markup and therefore\ncan't just reuse an existing form via ng-include or a form directive. What's even worse: Usually you already have\nthe validation logic in your back-end, but there is no easy way to share this information with the UI.\n\nvaldr solves these issues by extracting the validation constraints from the markup to a JSON structure. You define\nthe constraints per type and field, tell valdr that a form (or just a part of the form) belongs to a certain type and\nvaldr automatically validates the form fields.\n\nvaldr gives you the following advantages:\n- cleaner form markup\n- reusable validation constraints for your models -> easier to maintain\n- possibility to generate the constraints from the models you already have in your back-end (see [valdr-bean-validation](https://github.com/netceteragroup/valdr-bean-validation) for Java)\n- an easy way to display validation messages per form field\n- seamless integration with [angular-translate](https://github.com/angular-translate/angular-translate) for i18n of the validation messages\n\n## Install\n\n#### [Bower](http://bower.io)\n\n```bash\nbower install --save valdr\n```\n\n#### [NPM](http://www.npmjs.com)\n\n```bash\nnpm install valdr\n```\n\n## Getting started\n\n1) Add valdr.js to your index.html\n\n2) Add it as a dependency to your apps module:\n\n```javascript\nangular.module('yourApp', ['valdr']);\n```\n\n3) Define the constraints:\n```javascript\nyourApp.config(function(valdrProvider) {\n  valdrProvider.addConstraints({\n    'Person': {\n      'lastName': {\n        'size': {\n          'min': 2,\n          'max': 10,\n          'message': 'Last name must be between 2 and 10 characters.'\n        },\n        'required': {\n          'message': 'Last name is required.'\n        }\n      },\n      'firstName': {\n        'size': {\n          'min': 2,\n          'max': 20,\n          'message': 'First name must be between 2 and 20 characters.'\n        }\n      }\n    }\n});\n```\n\n4) Add the ```valdr-type``` directive in your form on any parent element of the input fields that you want to validate.\nThe **important** thing is, that the attribute ```name``` on the input field matches the field name in the constraints JSON.\n\n```html\n<form name=\"yourForm\" novalidate valdr-type=\"Person\">\n    <label for=\"lastName\">Last Name</label>\n    <input type=\"text\"\n           id=\"lastName\"\n           name=\"lastName\"\n           ng-model=\"person.lastName\">\n\n    <label for=\"firstName\">First Name</label>\n    <input type=\"text\"\n           id=\"firstName\"\n           name=\"firstName\"\n           ng-model=\"person.firstName\">\n</form>\n```\nThat's it. valdr will now automatically validate the fields with the defined constraints and set the ```$validity``` of these form items.\nAll violated constraints will be added to the ```valdrViolations``` array on those form items.\n\n## Constraints JSON\nThe JSON object to define the validation rules has the following structure:\n\n```javascript\n  TypeName {\n    FieldName {\n      ValidatorName {\n        <ValidatorArguments>\n        message: 'error message'\n      }\n    }\n  }\n```\n- **TypeName** The type of object (string)\n- **FieldName** The name of the field to validate (string)\n- **ValidatorName** The name of the validator (string) see below in the Built-In Validators section for the default validators\n- **ValidatorArguments** arguments which are passed to the validator, see below for the optional and required arguments for the built-in validators\n- **Message** the message which should be shown if the validation fails (can also be a message key if angular-translate is used)\n\nExample:\n```javascript\n  \"Person\": {\n    \"firstName\": {\n      \"size\": {\n        \"min\": 2,\n        \"max\": 20,\n        \"message\": \"First name must be between 2 and 20 characters.\"\n      }\n    }\n  },\n  \"Address\": {\n    \"email\": {\n      \"email\": {\n        \"message\": \"Must be a valid E-Mail address.\"\n      }\n    },\n    \"zipCode\": {\n      \"size\": {\n        \"min\": \"4\",\n        \"max\": \"6\",\n        \"message\": \"Zip code must be between 4 and 6 characters.\"\n      }\n    }\n  }\n```\n\n## Built-In Validators\n\n### size\nChecks the minimal and maximal length of the value.\n\nArguments:\n- **min** The minimal string length (number, optional, default 0)\n- **max** The maximal string length (number, optional)\n\n### minLength / maxLength\nChecks that the value is a string and not shorter / longer than the specified number of characters.\n\nArguments:\n- **number** The minimal / maximal string length (number, required)\n\n### min / max\nChecks that the value is a number above/below or equal to the specified number.\n\nArguments:\n- **value** The minimal / maximal value of the number (number, required)\n\n### required\nMarks the field as required.\n\n### pattern\nValidates the input using the specified regular expression.\n\nArguments:\n- **value** The regular expression (string/RegExp, required)\n\n### email\nChecks that the field contains a valid e-mail address. It uses the same regular expression as AngularJS is using for e-mail validation.\n\n### digits\nChecks that the value is a number with the specified number of integral/fractional digits.\n\nArguments:\n- **integer** The integral part of the number (number, required)\n- **fraction** The fractional part of the number (number, required)\n\n### url\nChecks that the value is a valid URL. It uses the same regular expression as AngularJS for the URL validation.\n\n### future / past\nCheck that the value is a date in the future/past. *NOTE* These validators require that [Moment.js](http://momentjs.com) is loaded.\n\n## Adding custom validators\nImplementing custom validation logic is easy, all you have to do is implement a validation service/factory and register it in the valdrProvider.\n\n1) Custom validator:\n```javascript\nyourApp.factory('customValidator', function () {\n  return {\n    name: 'customValidator', // this is the validator name that can be referenced from the constraints JSON\n    validate: function (value, arguments) {\n      // value: the value to validate\n      // arguments: the validator arguments\n      return value === arguments.onlyValidValue;\n    }\n  };\n});\n```\n2) Register it:\n```javascript\nyourApp.config(function (valdrProvider) {\n  valdrProvider.addValidator('customValidator');\n}\n```\n\n3) Use it in constraints JSON:\n```javascript\nyourApp.config(function (valdrProvider) {\n  valdrProvider.addConstraints({\n    'Person': {\n      'firstName': {\n        'customValidator': {\n          'onlyValidValue': 'Tom',\n          'message': 'First name has to be Tom!'\n        }\n      }\n    }\n  });\n}\n```\n\n## Applying validation to custom input widgets\nvaldr applies validation to ```<input>```, ```<textarea>``` and ```<select>``` HTML elements automatically if those\nelements are within a ```valdr-type``` block and there is ```ng-model``` bound to them. If you implemented your own\ninput widget or used one provided by a library (e.g. ui-select), you can still benefit from valdr validation applied to\nthat input widget. All you need is to decorate it with the ```enableValdrValidation``` directive. In addition to this,\nif you would like to make use of [validation messages](#showing-validation-messages-with-valdr-messages), add the\n```enableValdrMessage``` directive to the input widget:\n```html\n<form name=\"yourForm\" novalidate valdr-type=\"Person\">\n    <div valdr-form-group>\n        <label for=\"bestFriend\">Best Friend</label>\n        <my-select\n            id=\"bestFriend\"\n            name=\"bestFriend\"\n            ng-model=\"person.bestFriend\"\n            enable-valdr-validation\n            enable-valdr-message>\n           <!-- other my-select elements -->\n        </my-select>\n    </div>\n</form>\n```\n\n## Showing validation messages with ```valdr-messages```\nvaldr sets the AngularJS validation states like ```$valid```, ```$invalid``` and ```$error``` on all validated form\nelements and forms by default. Additional information like the violated constraints and the messages configured in the\nconstraints JSON are always set as ```valdrViolations``` array on the individual form items.\nWith this information, you can either write your own logic to display the validation messages, or use valdr-messages to\nautomatically show the messages next to the invalid form items.\n\nTo enable this behaviour, include ```valdr-message.js``` in your page (which is included in the bower package) and make\nuse of the ```valdr-form-group``` directive. This directive marks the element, where the valdr messages will be\nappended. The ```valdr-form-group``` can wrap multiple valdr validated form items. Each form item has to have at least\none surrounding ```valdr-form-group``` to automatically show validation messages.\n\n### Message template\nThe default message template to be used by valdr-messages can be overridden by configuring the ```valdrMessageProvider```:\n\n```javascript\nvaldrMessageProvider.setTemplate('<div class=\"valdr-message\">{{ violation.message }}</div>');\n\n// or\n\nvaldrMessageProvider.setTemplateUrl('/partials/valdrMesssageTemplate.html');\n```\n\nThe following variables will be available on the scope of the message template:\n- ```violations``` - an array of all violations for the current form field\n- ```violation``` - the first violation, if multiple constraints are violated it will be the one that is first declared in the JSON structure\n- ```formField``` - the invalid form field\n\n### CSS to control visibility\nvaldr sets some CSS classes on elements with the ```valdr-form-group``` directive and on the message elements which are\nautomatically added by ```valdr-messages```. These classes allow you to control the visibility of the validation\nmessages.\n\nTo change the CSS class names used by valdr, you can inject ```valdrClasses```and override the following values:\n\n```javascript\n{\n  // added on all elements with valdr-form-group directive\n  formGroup: 'form-group',\n  // added on valdr-form-group and on valdr-messages if all of the form items are valid\n  valid: 'ng-valid',\n  // added on valdr-form-group and on valdr-messages if one of the form items is invalid\n  invalid: 'ng-invalid',\n  // added on valdr-messages if the form item this message is associated with is dirty\n  dirty: 'ng-dirty',\n  // added on valdr-messages if the form item this message is associated with is pristine\n  pristine: 'ng-pristine',\n  // added on valdr-messages if the form item this message is associated with has been blurred\n  touched: 'ng-touched',\n  // added on valdr-messages if the form item this message is associated with has not been blurred\n  untouched: 'ng-untouched',\n  // added on valdr-form-group if one of the contained items is currently invalid, dirty and has been blurred\n  invalidDirtyTouchedGroup: 'valdr-invalid-dirty-touched-group'\n}\n```\n\nUsing CSS like the following, the messages can be shown only on inputs which the user changed, blurred and are invalid:\n\n```css\n.valdr-message {\n  display: none;\n}\n.valdr-message.ng-invalid.ng-touched.ng-dirty {\n  display: inline;\n  background: red;\n}\n```\n\n### Integration of angular-translate\nTo support i18n of the validation messages, valdr has built-in support for [angular-translate](https://github.com/angular-translate/angular-translate).\n\nInstead of adding the message directly to the constraints, use a message key and add the translations to the ```$translateProvider```.\nIn the translations, the constraint arguments and the field name can be used with placeholders as in the following\nexample:\n\n```javascript\nvaldrProvider.addConstraints({\n  'Person': {\n    'lastName': {\n      'size': {\n        'min': 5,\n        'max': 20,\n        'message': 'message.size'\n      }\n    }\n  }\n});\n\n$translateProvider.translations('en', {\n  'message.size': '{{fieldName}} must be between {{min}} and {{max}} characters.',\n  'Person.lastName': 'Last name'\n});\n\n$translateProvider.translations('de', {\n  'message.size': 'Zwischen {{min}} und {{max}} Zeichen sind im Feld {{fieldName}} erlaubt.',\n  'Person.lastName': 'Nachname'\n});\n```\n\n#### Custom field name translation keys\nBy default the translation key for the field name is put together as ```Type.Fieldname```, but\nsometimes your translations might be a bit more complicated and you need more freedom when\ngenerating your field names translation key. For example you would like to use an article in\nanother language to make it sound more natural.\n\nThis can be achieved by defining a `valdrFieldNameKeyGenerator` function like this:\n\n```javascript\nmodule.factory('valdrFieldNameSuffix', function() {\n  return function(violation) {\n    return violation.type + '.' + violation.field + '.' + violation.validator + 'Name';\n  }\n});\n\nvaldrProvider.addConstraints({\n  'Person': {\n    'lastName': {\n      'required': { 'message': 'message.required' }\n    }\n  }\n});\n\n$translateProvider.translations('en', {\n  'message.required': 'Please enter {{fieldName}}.',\n  'Person.lastName.requiredName' : 'the Last name'\n  }\n});\n\n$translateProvider.translations('de', {\n  'message.required': 'Bitte geben sie {{fieldName}} ein.',\n  'Person.lastName.requiredName': 'den Nachnamen'\n});\n```\n\n### Show messages for AngularJS built-in validators\nvaldr also allows to show messages for the AngularJS built-in validators like ```required``` and ```number```.\nTo enable this, set ```valdrMessage.angularMessagesEnabled``` to true in the run phase:\n\n```javascript\nvaldrMessage.angularMessagesEnabled = true;\n```\n\nAfter that, the messages can be registered by validator name in the ```valdrMessageProvider```:\n\n```javascript\nvaldrMessage.addMessages({\n  'required': 'This field is required.',\n  'number': 'Not a valid number.'\n});\n```\n\nTo register messages for specific fields, the type and the field name can be prepended:\n```javascript\nvaldrMessage.addMessages({\n  'Person.lastName.required': 'This last name is required.',\n  'Person.age.number': 'The age has to be a number.'\n});\n```\n\nWhen ```angular-translate``` is loaded it is also possible to register message keys instead of the messages.\n\nA complete example of mixed valdr and AngularJS validation can be found on the [demo page](demo/message/angular-validation.html).\n\n## Conditionally enable/disable validation\nThe ```valdrEnabled``` directive allows to dynamically enable and disable the validation with valdr. All form elements\nin a child node of an element with the 'valdr-enabled' directive will be affected by this.\n\nUsage:\n```html\n<div valdr-enabled=\"isValidationEnabled()\">\n  <input type=\"text\" name=\"name\" ng-model=\"mymodel.field\">\n</div>\n```\nIf multiple valdr-enabled directives are nested, the one nearest to the validated form element will take precedence.\n\n## Wire up your back-end\n\nTo load the validation constraints from your back-end, you can configure the ```valdrProvider``` in a ```config```\nfunction like this:\n\n```javascript\nyourApp.config(function(valdrProvider) {\n  valdrProvider.setConstraintUrl('/api/constraints');\n});\n```\n\n### Using JSR303 Bean Validation with Java back-ends\n\nIf you have a Java back-end and use Bean Validation (JSR 303) annotations, check out the [valdr-bean-validation](https://github.com/netceteragroup/valdr-bean-validation)\nproject. It parses Java model classes for Bean Validation constraints and extracts their information into a JSON document\nto be used by valdr. This allows to apply the exact same validation rules on the server and on the AngularJS client.\n\n### Using DataAnnotation with C# back-ends\n\nIf you have a c# back-end and use DataAnnotation, check out the [valdr-dotnet](https://github.com/netceteragroup/valdr-dotnet)\nproject. It parses C# classes for DataAnnotation attributes and extracts their information into into a JSON document\nto be used by valdr. This allows to apply the exact same validation rules on the server and on the AngularJS client.\n\n## Develop\n\nClone and install dependencies:\n\n```bash\ngit clone https://github.com/netceteragroup/valdr.git\ncd valdr\nnpm install\n```\n\nStart live-reload\n```bash\ngrunt dev\n```\n\nThen start the dev server\n```bash\ngrunt server\n```\n\nOpen [http://localhost:3005/demo](http://localhost:3005/demo) in your browser.\n\n## Support\n\n[Ask a question on Stack Overflow](http://stackoverflow.com/questions/ask?tags=valdr) and tag it with [`valdr`](http://stackoverflow.com/tags/valdr).\n\n## License\n\n[MIT](http://opensource.org/licenses/MIT) © Netcetera AG\n\n## Credits\nThanks a lot to [all contributors](https://github.com/netceteragroup/valdr/graphs/contributors) and the guys who brainstormed the name for this project over a dinner on [mount Rigi](https://maps.google.com/maps?q=Hotel+Rigi+Kaltbad&hl=en&cid=7481422441262508040&gl=US&hq=Hotel+Rigi+Kaltbad&t=m&z=16) with us.\n* [Björn Mosler](https://github.com/bjorm)\n* [Roland Weiss](https://github.com/rolego), father of 'valdr'\n* [Jason Brazile](https://github.com/jbrazile)\n"
  },
  {
    "path": "bower.json",
    "content": "{\n  \"author\": \"Netcetera AG\",\n  \"name\": \"valdr\",\n  \"description\": \"A model centric approach to AngularJS form validation\",\n  \"homepage\": \"https://github.com/netceteragroup/valdr\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/netceteragroup/valdr\"\n  },\n  \"devDependencies\": {\n    \"angular\": \"1.3.3\",\n    \"angular-mocks\": \"1.3.3\",\n    \"angular-translate\": \"2.4.2\",\n    \"jasmine\": \"1.3.0\",\n    \"momentjs\": \"2.8.3\"\n  }\n}\n"
  },
  {
    "path": "demo/core/custom-validator.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>Demo</title>\n</head>\n<body ng-app=\"demoApp\">\n\n<div ng-controller=\"TestController\">\n\n  <h1>Custom Validator Demo</h1>\n\n  <form name=\"demoForm\" novalidate valdr-type=\"Person\">\n      <div valdr-form-group>\n        <label for=\"lastName\">Last Name</label>\n        <input type=\"text\"\n               id=\"lastName\"\n               name=\"lastName\"\n               ng-model=\"person.lastName\">\n        <span>$valid {{ demoForm.lastName.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"firstName\">First Name</label>\n        <input type=\"text\"\n               id=\"firstName\"\n               name=\"firstName\"\n               ng-model=\"person.firstName\">\n        <span>$valid {{ demoForm.firstName.$valid }}</span>\n      </div>\n\n  </form>\n\n  <pre>demoForm.$valid: {{ demoForm.$valid }}</pre>\n\n  <h3>demoForm</h3>\n  <pre>{{ demoForm | json }}</pre>\n\n  <h3>constraints</h3>\n  <pre>{{ constraints | json }}</pre>\n\n</div>\n\n<script src=\"/bower_components/angular/angular.js\"></script>\n<script src=\"../js/valdr.js\"></script>\n<script src=\"http://localhost:35729/livereload.js\"></script>\n\n<script>\n  var demoApp = angular.module('demoApp', ['valdr']);\n\n  demoApp.factory('customValidator', function () {\n    return {\n      name: 'customValidator',\n      validate: function (value) {\n        return value === 'Hanueli';\n      }\n    };\n  });\n\n  demoApp.config(function (valdrProvider) {\n\n    valdrProvider.addValidator('customValidator');\n\n    valdrProvider.addConstraints({\n      'Person': {\n        'lastName': {\n          'required': {\n            'message': 'This field is required.'\n          }\n        },\n        'firstName': {\n          'customValidator': {\n            'message': 'First name must be Hanueli.'\n          }\n        }\n      }\n    });\n\n  });\n\n  demoApp.controller('TestController', function ($scope, valdr) {\n    $scope.person = {};\n\n    $scope.$watch(valdr.getConstraints, function (newConstraints) {\n      $scope.constraints = newConstraints;\n    });\n  });\n</script>\n</body>\n</html>\n"
  },
  {
    "path": "demo/core/list.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>Demo</title>\n\n  <style>\n    .demo-is-invalid label {\n      color: red;\n    }\n    .demo-is-valid label {\n      color: green;\n    }\n    .demo-is-invalid input {\n      background-color: red;\n    }\n  </style>\n</head>\n<body ng-app=\"demoApp\">\n\n<div ng-controller=\"TestController\">\n\n  <h1>List Demo</h1>\n\n  <form name=\"demoForm\" novalidate>\n\n    <div valdr-type=\"Person\">\n\n      <h4>Person</h4>\n      <div valdr-form-group>\n        <label for=\"firstName\">First Name</label>\n        <input type=\"text\"\n               id=\"firstName\"\n               name=\"firstName\"\n               ng-model=\"person.firstName\">\n        <span>$valid {{ demoForm.firstName.$valid }}</span>\n      </div>\n    </div>\n\n    <div ng-form=\"addressForm\" valdr-type=\"Address\" ng-repeat=\"address in person.addresses\">\n      <h4>Address {{ $index + 1 }} <button ng-click=\"removeAddress(address)\" >remove</button></h4>\n      <div valdr-form-group>\n        <label for=\"zipCode\">Zip Code</label>\n        <input type=\"text\"\n               id=\"zipCode\"\n               name=\"zipCode\"\n               ng-model=\"address.zipCode\">\n        <span>$valid {{ addressForm.zipCode.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"email\">E-Mail</label>\n        <input type=\"text\"\n               id=\"email\"\n               name=\"email\"\n               ng-model=\"address.email\">\n        <span>$valid {{ addressForm.email.$valid }}</span>\n      </div>\n      <pre>{{ addressForm | json }}</pre>\n    </div>\n\n  </form>\n\n  <button ng-click=\"addAddress()\">Add address</button>\n  <pre>demoForm.$valid: {{ demoForm.$valid }}</pre>\n\n  <h3>demoForm</h3>\n  <pre>{{ demoForm | json }}</pre>\n\n  <h3>constraints</h3>\n  <pre>{{ constraints | json }}</pre>\n\n</div>\n\n<script src=\"/bower_components/angular/angular.js\"></script>\n<script src=\"../js/valdr.min.js\"></script>\n<script src=\"http://localhost:35729/livereload.js\"></script>\n\n<script>\n  var demoApp = angular.module('demoApp', ['valdr']);\n\n  demoApp.config(function (valdrProvider) {\n    valdrProvider.addConstraints({\n      'Person': {\n        'firstName': {\n          'size': {\n            'min': 2,\n            'max': 20,\n            'message': 'First name must be between 2 and 20 characters.'\n          }\n        }\n      },\n      'Address': {\n        'email': {\n          'email': {\n            'message': 'Must be a valid E-Mail address.'\n          }\n        },\n        'zipCode': {\n          'size': {\n            'min': '4',\n            'max': '6',\n            'message': 'Zip code must be between 4 and 6 characters.'\n          }\n        }\n      }\n    });\n  });\n\n  demoApp.controller('TestController', function ($scope, valdr) {\n    // use custom classes on the surrounding elements\n    valdr.setClasses({\n      valid: 'demo-is-valid',\n      invalid: 'demo-is-invalid'\n    });\n\n    $scope.person = {\n      addresses: []\n    };\n\n    $scope.constraints = valdr.getConstraints();\n\n    $scope.addAddress = function () {\n      $scope.person.addresses.push({});\n    };\n\n    $scope.removeAddress = function(address) {\n      var index = $scope.person.addresses.indexOf(address);\n      $scope.person.addresses.splice(index, 1);\n    };\n  });\n</script>\n</body>\n</html>\n"
  },
  {
    "path": "demo/core/load-constraints.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>Demo</title>\n</head>\n<body ng-app=\"demoApp\">\n\n<div ng-controller=\"TestController\">\n\n  <h1>Async Demo</h1>\n\n  <form name=\"demoForm\" novalidate>\n\n    <div valdr-type=\"Person\">\n\n      <div valdr-form-group ng-form>\n        <label for=\"lastName\">Last Name</label>\n        <input type=\"text\"\n               id=\"lastName\"\n               name=\"lastName\"\n               ng-model=\"person.lastName\">\n        <span>$valid {{ demoForm.lastName.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"firstName\">First Name</label>\n        <input type=\"text\"\n               id=\"firstName\"\n               name=\"firstName\"\n               ng-model=\"person.firstName\">\n        <span>$valid {{ demoForm.firstName.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"zipCode\">Zip Code</label>\n        <input type=\"text\"\n               id=\"zipCode\"\n               name=\"zipCode\"\n               ng-model=\"person.zipCode\">\n        <span>$valid {{ demoForm.zipCode.$valid }}</span>\n      </div>\n\n    </div>\n\n  </form>\n\n  <pre>demoForm.$valid: {{ demoForm.$valid }}</pre>\n\n  <h3>demoForm</h3>\n  <pre>{{ demoForm | json }}</pre>\n\n  <h3>constraints</h3>\n  <pre>{{ constraints | json }}</pre>\n\n</div>\n\n<script src=\"/bower_components/angular/angular.js\"></script>\n<script src=\"../js/valdr.js\"></script>\n<script src=\"http://localhost:35729/livereload.js\"></script>\n\n<script>\n  var demoApp = angular.module('demoApp', ['valdr']);\n\n  demoApp.config(function(valdrProvider) {\n    valdrProvider.setConstraintUrl('/api/constraints');\n  });\n\n  demoApp.controller('TestController', function ($scope, valdr) {\n    $scope.person = {};\n\n    $scope.$watch(valdr.getConstraints, function (newConstraints) {\n      $scope.constraints = newConstraints;\n    });\n  });\n</script>\n</body>\n</html>\n"
  },
  {
    "path": "demo/core/simple.html",
    "content": "<!DOCTYPE html>\n<html>\n\n<head>\n  <title>Demo</title>\n</head>\n\n<body ng-app=\"demoApp\">\n\n<div ng-controller=\"TestController\">\n\n  <h1>Simple Demo</h1>\n\n  <form name=\"demoForm\" novalidate valdr-enabled=\"isValdrEnabled\">\n\n    <div valdr-type=\"Person\">\n\n      <h4>Person</h4>\n      <div valdr-form-group valdr-enabled=\"true\">\n        <label for=\"lastName\">Last Name</label>\n        <input type=\"text\"\n               id=\"lastName\"\n               name=\"lastName\"\n               ng-model=\"person.lastName\">\n        <span>$valid {{ demoForm.lastName.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"firstName\">First Name</label>\n        <input type=\"text\"\n               id=\"firstName\"\n               name=\"firstName\"\n               ng-model=\"person.firstName\">\n        <span>$valid {{ demoForm.firstName.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"age\">Age</label>\n        <input type=\"number\"\n               id=\"age\"\n               name=\"age\"\n               ng-model=\"person.age\">\n        <span>$valid {{ demoForm.age.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"gender\">Gender</label>\n        <select id=\"gender\"\n               name=\"gender\"\n               ng-options=\"gender as gender.label for gender in genders\"\n               ng-model=\"person.gender\">\n          <option value=\"\"></option>\n        </select>\n        <span>$valid {{ demoForm.gender.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"bio\">Bio</label>\n        <textarea\n               id=\"bio\"\n               name=\"bio\"\n               ng-model=\"person.bio\"\n               rows=\"3\"></textarea>\n        <span>$valid {{ demoForm.bio.$valid }}</span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"homepage\">Homepage</label>\n        <input type=\"text\"\n               id=\"homepage\"\n               name=\"homepage\"\n               ng-model=\"person.homepage\">\n        <span>$valid {{ demoForm.homepage.$valid }}</span>\n      </div>\n\n      <h4>Address</h4>\n      <div valdr-type=\"Address\">\n        <div valdr-form-group>\n          <label for=\"zipCode\">Zip Code</label>\n          <input type=\"text\"\n                 id=\"zipCode\"\n                 name=\"zipCode\"\n                 ng-model=\"person.address.zipCode\">\n          <span>$valid {{ demoForm.zipCode.$valid }}</span>\n        </div>\n\n        <div valdr-form-group>\n          <label for=\"email\">E-Mail</label>\n          <input type=\"text\"\n                 id=\"email\"\n                 name=\"email\"\n                 ng-model=\"person.address.email\">\n          <span>$valid {{ demoForm.email.$valid }}</span>\n        </div>\n      </div>\n    </div>\n\n  </form>\n\n  <h3>Settings</h3>\n\n  <button ng-click=\"addAddressConstraints()\">Add address constraints</button>\n\n  <div>\n    <label for=\"enabled\">Enable/Disable valdr (except last name)</label>\n    <input id=\"enabled\" type=\"checkbox\" ng-model=\"isValdrEnabled\">\n  </div>\n\n  <button ng-click=\"removeConstraints()\">Remove all constraints</button>\n\n  <pre>demoForm.$valid: {{ demoForm.$valid }}</pre>\n\n  <h3>demoForm</h3>\n  <pre>{{ demoForm | json }}</pre>\n\n  <h3>constraints</h3>\n  <pre>{{ constraints | json }}</pre>\n\n</div>\n\n<script src=\"/bower_components/angular/angular.js\"></script>\n<script src=\"../js/valdr.js\"></script>\n<script src=\"http://localhost:35729/livereload.js\"></script>\n\n<script>\n  var demoApp = angular.module('demoApp', ['valdr']);\n\n  demoApp.config(function(valdrProvider) {\n    valdrProvider.addConstraints({\n      'Person': {\n        'lastName': {\n          'size': {\n            'min': 2,\n            'max': 10,\n            'message': 'Last name must be between 2 and 10 characters.'\n          },\n          'required': {\n            'message': 'Last name is required.'\n          }\n        },\n        'firstName': {\n          'size': {\n            'min': 2,\n            'max': 20,\n            'message': 'First name must be between 2 and 20 characters.'\n          }\n        },\n        'age': {\n          'min': {\n            value: '21',\n            message: 'Must be 21 years old.'\n          },\n          'required': {\n            message: 'Age is required.'\n          }\n        },\n        'gender': {\n          'required': {\n            message: 'Gender is required.'\n          }\n        },\n        'bio': {\n          'size': {\n            max: 20,\n            message: 'Bio can not be longer than 20 characters.'\n          }\n        },\n        'homepage': {\n          'url': {\n            message: 'Must be a valid URL.'\n          }\n        }\n      }\n    });\n  });\n\n  demoApp.controller('TestController', function ($scope, valdr) {\n    $scope.person = {};\n\n    $scope.genders = [\n      { label: 'Male', value: 1 },\n      { label: 'Female', value: 2 }\n    ];\n    $scope.constraints = valdr.getConstraints();\n\n    $scope.isValdrEnabled = true;\n\n    $scope.removeConstraints = function () {\n      valdr.removeConstraints('Person');\n    };\n\n    $scope.addAddressConstraints = function () {\n\n      valdr.addConstraints({\n        'Address': {\n          'email': {\n            'email': {\n              'message': 'Must be a valid E-Mail address.'\n            }\n          },\n          'zipCode': {\n            'pattern': {\n              'value': /^\\d{4}$/,\n              'message': 'Zip code must be 4 digits.'\n            }\n          }\n        }\n      });\n      $scope.constraints = valdr.getConstraints();\n    };\n\n  });\n</script>\n</body>\n</html>\n"
  },
  {
    "path": "demo/demo-api.js",
    "content": "module.exports = function (app) {\n\n  var url = require('url'),\n      fs = require('fs');\n\n  var getConstraints = function (req, res) {\n    function answer(code, data) {\n      res.writeHead(code,{\n        'Content-Type':'application/json;charset=utf-8',\n        'Access-Control-Allow-Origin':'*',\n        'Access-Control-Allow-Headers':'X-Requested-With'\n      });\n      res.end(data);\n    }\n\n    fs.readFile('./demo/demoConstraints.json', function(err, data) {\n      if (err) answer(404, '');\n      else answer(200, data);\n    });\n  };\n\n  app.get('/api/constraints', getConstraints);\n\n};"
  },
  {
    "path": "demo/demoConstraints.json",
    "content": "{\n  \"Person\": {\n    \"lastName\": {\n      \"size\": {\n        \"min\": 2,\n        \"max\": 10,\n        \"message\": \"javax.validation.constraints.Size.message\"\n      }\n    },\n    \"firstName\": {\n      \"size\": {\n        \"min\": 2,\n        \"max\": 20,\n        \"message\": \"javax.validation.constraints.Size.message\"\n      }\n    },\n    \"zipCode\": {\n      \"size\": {\n        \"min\": 4,\n        \"max\": 4,\n        \"message\": \"javax.validation.constraints.Size.message\"\n      }\n    }\n  }\n}"
  },
  {
    "path": "demo/index.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>valdr demos</title>\n</head>\n<body>\n\n<h2>Core</h2>\n<ul>\n  <li><a href=\"core/simple.html\">Simple</a></li>\n  <li><a href=\"core/list.html\">List</a></li>\n  <li><a href=\"core/load-constraints.html\">Load constraints</a></li>\n  <li><a href=\"core/custom-validator.html\">Custom validator</a></li>\n</ul>\n\n<h2>Validation Messages</h2>\n<ul>\n  <li><a href=\"message/simple.html\">Simple</a></li>\n  <li><a href=\"message/angular-validation.html\">Messages for AngularJS validators</a></li>\n  <li><a href=\"message/angular-translate.html\">i18n with angular-translate</a></li>\n</ul>\n\n</body>\n</html>\n"
  },
  {
    "path": "demo/message/angular-translate.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>Demo</title>\n</head>\n<body ng-app=\"demoApp\">\n\n<div ng-controller=\"TestController\">\n\n  <h1>angular-translate Demo</h1>\n\n  <ul>\n    <li><a href=\"\" ng-click=\"changeLanguage('en')\">english</a></li>\n    <li><a href=\"\" ng-click=\"changeLanguage('de')\">german</a></li>\n  </ul>\n\n  <form name=\"demoForm\" novalidate>\n\n    <div valdr-type=\"Person\">\n\n      <h4>Person</h4>\n      <div valdr-form-group>\n        <label for=\"lastName\">Last Name</label>\n        <div class=\"some-class\">\n          <input type=\"text\"\n                 id=\"lastName\"\n                 name=\"lastName\"\n                 ng-model=\"person.lastName\">\n        </div>\n\n        <pre>{{ demoForm.lastName.valdrViolations | json }}</pre>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"firstName\">First Name</label>\n        <input type=\"text\"\n               id=\"firstName\"\n               name=\"firstName\"\n               ng-model=\"person.firstName\">\n      </div>\n\n    </div>\n  </form>\n\n  <h3>constraints</h3>\n  <pre>{{ constraints | json }}</pre>\n\n</div>\n\n<script src=\"/bower_components/angular/angular.js\"></script>\n<script src=\"/bower_components/angular-translate/angular-translate.js\"></script>\n<script src=\"../js/valdr.js\"></script>\n<script src=\"../js/valdr-message.js\"></script>\n<script src=\"http://localhost:35729/livereload.js\"></script>\n\n<script>\n  var demoApp = angular.module('demoApp', ['valdr', 'pascalprecht.translate']);\n\n  demoApp.config(function(valdrProvider, valdrMessageProvider, $translateProvider) {\n\n    valdrProvider.addConstraints({\n      'Person': {\n        'lastName': {\n          'required': {\n            'message': 'message.required'\n          },\n          'size': {\n            'min': 5,\n            'max': 20,\n            'message': 'message.size'\n          }\n        },\n        'firstName': {\n          'size': {\n            'min': 3,\n            'max': 10,\n            'message': 'message.size'\n          }\n        }\n      }\n    });\n\n    $translateProvider.translations('en', {\n      'message.required': '{{fieldName}} is required.',\n      'message.size': '{{fieldName}} must be between {{min}} and {{max}} characters.',\n      'Person.lastName': 'Last name',\n      'Person.firstName': 'First name'\n    });\n\n    $translateProvider.translations('de', {\n      'message.required': '{{fieldName}} ist ein Pflichtfeld.',\n      'message.size': 'Zwischen {{min}} und {{max}} Zeichen sind im Feld {{fieldName}} erlaubt.',\n      'Person.lastName': 'Nachname',\n      'Person.firstName': 'Vorname'\n    });\n\n    $translateProvider.preferredLanguage('en');\n  });\n\n  demoApp.controller('TestController', function ($scope, valdr, $translate) {\n    $scope.person = {};\n    $scope.constraints = valdr.getConstraints();\n\n    $scope.changeLanguage = function (key) {\n      $translate.use(key);\n    };\n  });\n</script>\n</body>\n</html>\n"
  },
  {
    "path": "demo/message/angular-validation.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>Demo</title>\n\n  <style>\n    .valdr-message {\n        display: inline;\n        background: red;\n    }\n\n    input.ng-invalid {\n      background: red;\n    }\n    .form-group.ng-invalid label {\n      color: red;\n    }\n  </style>\n</head>\n<body ng-app=\"demoApp\">\n\n<div ng-controller=\"TestController\" ng-class=\"{ 'form-submitted': formSubmitted }\">\n\n  <h1>AngularJS validation messages</h1>\n\n  <p>This example shows that by using valdrMessage it is possible to register validation messages\n    for both AngularJS built-in and valdr validators.</p>\n\n  <p> The last name field has AngularJS and valdr validators, while the age field is of type number and therefore\n    is automatically validated by the AngularJS number validator.</p>\n\n  <form name=\"demoForm\" novalidate>\n\n    <div valdr-type=\"Person\">\n\n      <h4>Person</h4>\n      <div valdr-form-group>\n        <label for=\"lastName\">Last Name</label>\n        <input type=\"text\"\n               id=\"lastName\"\n               name=\"lastName\"\n               required\n               ng-minlength=\"2\"\n               ng-model=\"person.lastName\">\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"age\">Age</label>\n        <input type=\"number\"\n               id=\"age\"\n               name=\"age\"\n               ng-model=\"person.age\">\n      </div>\n\n    </div>\n\n  </form>\n\n  <pre>demoForm.$valid = {{demoForm.$valid}}</pre>\n\n  <h3>constraints:</h3>\n  <pre>{{ constraints | json }}</pre>\n\n</div>\n\n<script src=\"/bower_components/angular/angular.js\"></script>\n<script src=\"/bower_components/angular-translate/angular-translate.js\"></script>\n<script src=\"../js/valdr.js\"></script>\n<script src=\"../js/valdr-message.js\"></script>\n<script src=\"http://localhost:35729/livereload.js\"></script>\n\n<script>\n  var demoApp = angular.module('demoApp', ['valdr', 'pascalprecht.translate']);\n\n  demoApp.config(function(valdrProvider) {\n\n    valdrProvider.addConstraints({\n      'Person': {\n        'lastName': {\n          'size': {\n            'max': 4,\n            'message': 'Last name max is 4 characters.'\n          }\n        }\n      }\n    });\n  });\n\n  demoApp.config(function (valdrMessageProvider, $translateProvider) {\n    $translateProvider.translations('en', {\n      'message.required': '{{fieldName}} is required.',\n      'message.number': '{{fieldName}} must be a number.',\n      'lastname.specific': '{{fieldName}} min is 2 characters.',\n      'Person.lastName': 'Last name',\n      'Person.age': 'Age'\n    });\n\n    $translateProvider.preferredLanguage('en');\n\n    valdrMessageProvider.addMessages({\n      'required': 'message.required',\n      'number': 'message.number',\n      'Person.lastName.minlength': 'lastname.specific'\n    });\n\n  });\n\n  demoApp.run(function (valdrMessage) {\n    valdrMessage.angularMessagesEnabled = true;\n  });\n\n  demoApp.controller('TestController', function ($scope, valdr) {\n\n    $scope.person = {};\n    $scope.genders = [\n      { label: 'Male', value: 1 },\n      { label: 'Female', value: 2 }\n    ];\n    $scope.constraints = valdr.getConstraints();\n\n    $scope.showAllErrors = function () {\n        $scope.formSubmitted = true;\n    }\n  });\n</script>\n</body>\n</html>\n"
  },
  {
    "path": "demo/message/message-template.tpl.html",
    "content": "<div class=\"my-violations\">\n  <p class=\"some-custom-class\" ng-repeat=\"violation in violations\">\n    {{ violation.message }} {{ violation | json }}\n  </p>\n</div>"
  },
  {
    "path": "demo/message/simple.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>Demo</title>\n\n  <style>\n    .valdr-message {\n        display: none;\n    }\n    .valdr-message.ng-invalid.ng-dirty.ng-touched, .form-submitted .valdr-message.ng-invalid {\n        display: inline;\n        background: red;\n    }\n    input.ng-invalid.ng-dirty.ng-touched, .form-submitted input.ng-invalid {\n      background: red;\n    }\n    .valdr-invalid-dirty-touched-group label, .form-submitted .form-group.ng-invalid label {\n      color: red;\n    }\n  </style>\n</head>\n<body ng-app=\"demoApp\">\n\n<div ng-controller=\"TestController\" ng-class=\"{ 'form-submitted': formSubmitted }\">\n\n  <h1>Message Demo</h1>\n\n  <form name=\"demoForm2\" novalidate>\n\n    <div valdr-type=\"Person\">\n\n      <h4>Person</h4>\n      <div valdr-form-group>\n        <label for=\"lastName\">Last Name</label>\n        <input type=\"text\"\n               id=\"lastName\"\n               name=\"lastName\"\n               ng-model=\"person.lastName\">\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"firstName\">First Name</label>\n        <input type=\"text\"\n               id=\"firstName\"\n               name=\"firstName\"\n               ng-model=\"person.firstName\"\n               valdr-no-message>\n        <span><em>Error message disabled for this field.</em></span>\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"age\">Age</label>\n        <input type=\"number\"\n               id=\"age\"\n               name=\"age\"\n               ng-model=\"person.age\">\n      </div>\n\n      <div valdr-form-group>\n        <label for=\"gender\">Gender</label>\n        <select id=\"gender\"\n                name=\"gender\"\n                ng-options=\"gender as gender.label for gender in genders\"\n                ng-model=\"person.gender\">\n          <option value=\"\"></option>\n        </select>\n      </div>\n\n      <label for=\"showZipCity\">Show Zip/City </label>\n      <input id=\"showZipCity\" name=\"showZipCity\" ng-model=\"showZipCity\" type=\"checkbox\">\n\n      <div valdr-form-group>\n        <div ng-if=\"showZipCity\">\n            <label for=\"zip\">Zip / City</label>\n            <input type=\"text\"\n               id=\"zip\"\n               name=\"zip\"\n               ng-model=\"person.zip\">\n            <input type=\"text\"\n               id=\"city\"\n               name=\"city\"\n               ng-model=\"person.city\">\n        </div>\n      </div>\n\n    </div>\n\n  </form>\n\n  <button ng-click=\"showAllErrors()\">Show all errors</button>\n\n  <h3>constraints</h3>\n  <pre>{{ constraints | json }}</pre>\n\n</div>\n\n<script src=\"/bower_components/angular/angular.js\"></script>\n<script src=\"../js/valdr.js\"></script>\n<script src=\"../js/valdr-message.js\"></script>\n<script src=\"http://localhost:35729/livereload.js\"></script>\n\n<script>\n  var demoApp = angular.module('demoApp', ['valdr']);\n\n  demoApp.config(function(valdrProvider) {\n\n    valdrProvider.addConstraints({\n      'Person': {\n        'lastName': {\n          'required': {\n            'message': 'Last name is required.'\n          },\n          'size': {\n            'min': 2,\n            'max': 10,\n            'message': 'Last name must be between 2 and 10 characters.'\n          }\n        },\n        'firstName': {\n          'size': {\n            'min': 2,\n            'max': 20,\n            'message': 'First name must be between 2 and 20 characters.'\n          }\n        },\n        'age': {\n          'min': {\n            value: '21',\n            message: 'Person must be 21 years old.'\n          }\n        },\n        'gender': {\n          'required': {\n            'message': 'Gender is required.'\n          }\n        },\n        'zip': {\n          'size': {\n              'min': 4,\n              'max': 6,\n              'message': 'ZIP must be between 4 and 6 characters.'\n          }\n        },\n        'city': {\n          'size': {\n              'min': 1,\n              'max': 10,\n              'message': 'City must be between 1 and 10 characters.'\n          }\n        }\n      }\n    });\n  });\n\n  demoApp.controller('TestController', function ($scope, valdr) {\n    $scope.person = {};\n    $scope.genders = [\n      { label: 'Male', value: 1 },\n      { label: 'Female', value: 2 }\n    ];\n    $scope.constraints = valdr.getConstraints();\n\n    $scope.showAllErrors = function () {\n        $scope.formSubmitted = true;\n    }\n  });\n</script>\n</body>\n</html>\n"
  },
  {
    "path": "js.prefix",
    "content": "(function (window, document) {\n'use strict';\n"
  },
  {
    "path": "js.suffix",
    "content": "})(window, document);"
  },
  {
    "path": "karma.conf.js",
    "content": "module.exports = function (config) {\n  config.set({\n\n    basePath: '',\n\n    frameworks: ['jasmine'],\n\n    files: [\n      'bower_components/angular/angular.js',\n      'bower_components/angular-translate/angular-translate.js',\n      'bower_components/angular-mocks/angular-mocks.js',\n      'bower_components/momentjs/moment.js',\n      'src/valdr.js',\n      'src/**/*.js',\n      'src/**/*.spec.js'\n    ],\n\n    exclude: [],\n\n    reporters: ['progress', 'coverage', 'coveralls'],\n\n    port: 9876,\n\n    colors: true,\n\n    // LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG\n    logLevel: config.LOG_INFO,\n\n    // Start these browsers, currently available:\n    // - Chrome\n    // - ChromeCanary\n    // - Firefox\n    // - Opera\n    // - Safari (only Mac)\n    // - PhantomJS\n    // - IE (only Windows)\n    browsers: [process.env.TRAVIS ? 'Firefox' : 'Chrome'],\n\n    captureTimeout: 60000,\n\n    singleRun: false,\n\n    preprocessors: {\n      'src/**/!(*.spec)+(.js)': ['coverage']\n    },\n\n    coverageReporter: {\n      type: 'lcov',\n      dir: 'coverage/'\n    },\n\n    plugins: [\n      'karma-jasmine',\n      'karma-chrome-launcher',\n      'karma-firefox-launcher',\n      'karma-phantomjs-launcher',\n      'karma-coverage',\n      'karma-coveralls'\n    ]\n  });\n};\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"valdr\",\n  \"version\": \"1.1.6\",\n  \"description\": \"A model centric approach to AngularJS form validation\",\n  \"homepage\": \"https://github.com/netceteragroup/valdr\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git://github.com/netceteragroup/valdr\"\n  },\n  \"scripts\": {\n    \"postinstall\": \"bower install\"\n  },\n  \"author\": {\n    \"name\": \"Netcetera AG\"\n  },\n  \"license\": \"MIT\",\n  \"devDependencies\": {\n    \"bower\": \"~1.3.12\",\n    \"karma\": \"~0.12.31\",\n    \"karma-jasmine\": \"~0.1.5\",\n    \"karma-chrome-launcher\": \"~0.1.7\",\n    \"karma-firefox-launcher\": \"~0.1.4\",\n    \"karma-phantomjs-launcher\": \"0.1.4\",\n    \"karma-coverage\": \"~0.2.7\",\n    \"karma-coveralls\": \"~0.1.4\",\n    \"grunt\": \"~0.4.5\",\n    \"grunt-karma\": \"~0.8.2\",\n    \"grunt-contrib-copy\": \"~0.7.0\",\n    \"grunt-contrib-clean\": \"~0.6.0\",\n    \"grunt-contrib-concat\": \"~0.5.0\",\n    \"grunt-contrib-uglify\": \"~0.7.0\",\n    \"grunt-contrib-jshint\": \"~0.10.0\",\n    \"grunt-contrib-watch\": \"~0.6.1\",\n    \"load-grunt-tasks\": \"~2.0.0\",\n    \"express\": \"~3.4.8\",\n    \"grunt-express\": \"~1.2.1\"\n  }\n}\n"
  },
  {
    "path": "server.js",
    "content": "var express = require('express');\n\nvar app = express();\nvar server = require('http').createServer(app);\n\napp.configure(function () {\n    app.use(express.logger('dev'));\n    app.use(express.bodyParser());\n    app.use(express.methodOverride());\n    app.use(express.errorHandler());\n    app.use(express.static(__dirname));\n    app.use(app.router);\n    require('./demo/demo-api')(app, __dirname);\n});\n\nmodule.exports = server;\n\n// Override: Provide an \"use\" used by grunt-express.\nmodule.exports.use = function () {\n    app.use.apply(app, arguments);\n};\n"
  },
  {
    "path": "src/core/valdr-service.js",
    "content": "angular.module('valdr')\n\n  .provider('valdr', function () {\n\n    var constraints = {}, validators = {}, constraintUrl, constraintsLoading, constraintAliases = {},\n      validatorNames = [\n        'valdrRequiredValidator',\n        'valdrSizeValidator',\n        'valdrMinLengthValidator',\n        'valdrMaxLengthValidator',\n        'valdrMinValidator',\n        'valdrMaxValidator',\n        'valdrEmailValidator',\n        'valdrUrlValidator',\n        'valdrDigitsValidator',\n        'valdrFutureValidator',\n        'valdrPastValidator',\n        'valdrPatternValidator',\n        'valdrHibernateEmailValidator'\n      ];\n\n    var addConstraints = function (newConstraints) {\n      angular.extend(constraints, newConstraints);\n    };\n\n    this.addConstraints = addConstraints;\n\n    var removeConstraints = function (constraintNames) {\n      if (angular.isArray(constraintNames)) {\n        angular.forEach(constraintNames, function (name) {\n          delete constraints[name];\n        });\n      } else if (angular.isString(constraintNames)) {\n        delete constraints[constraintNames];\n      }\n    };\n\n    this.removeConstraints = removeConstraints;\n\n    this.setConstraintUrl = function (url) {\n      constraintUrl = url;\n    };\n\n    this.addValidator = function (validatorName) {\n      validatorNames.push(validatorName);\n    };\n\n    this.addConstraintAlias = function (valdrName, alias) {\n      if(!angular.isArray(constraintAliases[valdrName])) {\n        constraintAliases[valdrName] = [];\n      }\n      constraintAliases[valdrName].push(alias);\n    };\n\n    this.$get =\n      ['$log', '$injector', '$rootScope', '$http', 'valdrEvents', 'valdrUtil', 'valdrClasses',\n        function ($log, $injector, $rootScope, $http, valdrEvents, valdrUtil, valdrClasses) {\n\n          // inject all validators\n          angular.forEach(validatorNames, function (validatorName) {\n            var validator = $injector.get(validatorName);\n            validators[validator.name] = validator;\n\n            // register validator with aliases\n            if(angular.isArray(constraintAliases[validator.name])) {\n              angular.forEach(constraintAliases[validator.name], function (alias) {\n                validators[alias] = validator;\n              });\n            }\n\n          });\n\n          // load constraints via $http if constraintUrl is configured\n          if (constraintUrl) {\n            constraintsLoading = true;\n            $http.get(constraintUrl).then(function (response) {\n              constraintsLoading = false;\n              addConstraints(response.data);\n              $rootScope.$broadcast(valdrEvents.revalidate);\n            })['finally'](function () {\n              constraintsLoading = false;\n            });\n          }\n\n          var constraintsForType = function (type) {\n            if (valdrUtil.has(constraints, type)) {\n              return constraints[type];\n            } else if (!constraintsLoading) {\n              $log.warn('No constraints for type \\'' + type + '\\' available.');\n            }\n          };\n\n          return {\n            /**\n             * Validates the value of the given type with the constraints for the given field name.\n             *\n             * @param typeName the type name\n             * @param fieldName the field name\n             * @param value the value to validate\n             * @returns {*}\n             */\n            validate: function (typeName, fieldName, value) {\n\n              var validResult = { valid: true },\n                typeConstraints = constraintsForType(typeName);\n\n              if (valdrUtil.has(typeConstraints, fieldName)) {\n                var fieldConstraints = typeConstraints[fieldName],\n                  fieldIsValid = true,\n                  validationResults = [],\n                  violations = [];\n\n                angular.forEach(fieldConstraints, function (constraint, validatorName) {\n                  var validator = validators[validatorName];\n\n                  if (angular.isUndefined(validator)) {\n                    $log.warn('No validator defined for \\'' + validatorName +\n                      '\\'. Can not validate field \\'' + fieldName + '\\'');\n                    return validResult;\n                  }\n\n                  var valid = validator.validate(value, constraint);\n                  var validationResult = {\n                    valid: valid,\n                    value: value,\n                    field: fieldName,\n                    type: typeName,\n                    validator: validatorName\n                  };\n                  angular.extend(validationResult, constraint);\n\n                  validationResults.push(validationResult);\n                  if (!valid) {\n                    violations.push(validationResult);\n                  }\n                  fieldIsValid = fieldIsValid && valid;\n                });\n\n                return {\n                  valid: fieldIsValid,\n                  violations: violations.length === 0 ? undefined : violations,\n                  validationResults: validationResults.length === 0 ? undefined : validationResults\n                };\n              } else {\n                return validResult;\n              }\n            },\n            addConstraints: function (newConstraints) {\n              addConstraints(newConstraints);\n              $rootScope.$broadcast(valdrEvents.revalidate);\n            },\n            removeConstraints: function (constraintNames) {\n              removeConstraints(constraintNames);\n              $rootScope.$broadcast(valdrEvents.revalidate);\n            },\n            getConstraints: function () {\n              return constraints;\n            },\n            setClasses: function (newClasses) {\n              angular.extend(valdrClasses, newClasses);\n              $rootScope.$broadcast(valdrEvents.revalidate);\n            }\n          };\n        }];\n  });"
  },
  {
    "path": "src/core/valdr-service.spec.js",
    "content": "describe('valdr', function () {\n\n  var valdr, $rootScope, valdrEvents, valdrClasses, sizeValidator, requiredValidator,\n    personConstraints = {\n      'Person': {\n        'firstName': {\n          'size': {\n            'min': 0,\n            'max': 10,\n            'message': 'size'\n          }\n        }\n      }\n    },\n    addressConstraints = {\n      'Address': {\n        'street': {\n          'required': {\n            'message': 'required'\n          }\n        }\n      }\n    };\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(\n    function (_valdr_, _$rootScope_, _valdrEvents_, _valdrClasses_, _valdrSizeValidator_, _valdrRequiredValidator_) {\n    valdr = _valdr_;\n    $rootScope = _$rootScope_;\n    valdrEvents = _valdrEvents_;\n    valdrClasses = _valdrClasses_;\n    sizeValidator = _valdrSizeValidator_;\n    requiredValidator = _valdrRequiredValidator_;\n  }));\n\n  describe('addConstraints()', function () {\n\n    it('should add initial constraints', function () {\n      // when\n      valdr.addConstraints(personConstraints);\n\n      // then\n      expect(valdr.getConstraints()).toEqual(personConstraints);\n    });\n\n    it('should extend initial constraints', function () {\n      // when\n      valdr.addConstraints(personConstraints);\n      valdr.addConstraints(addressConstraints);\n\n      // then\n      expect(valdr.getConstraints().Person).toEqual(personConstraints.Person);\n      expect(valdr.getConstraints().Address).toEqual(addressConstraints.Address);\n    });\n\n    it('should broadcast event when constraints change', function () {\n      // given\n      spyOn($rootScope, '$broadcast');\n\n      // when\n      valdr.addConstraints(personConstraints);\n\n      // then\n      expect($rootScope.$broadcast).toHaveBeenCalledWith(valdrEvents.revalidate);\n    });\n  });\n\n  describe('removeConstraints()', function () {\n\n    it('should remove single constraint', function () {\n      // given\n      valdr.addConstraints(personConstraints);\n      valdr.addConstraints(addressConstraints);\n\n      // when\n      valdr.removeConstraints('Person');\n\n      // then\n      expect(valdr.getConstraints()).toEqual(addressConstraints);\n    });\n\n    it('should remove multiple constraints', function () {\n      // given\n      valdr.addConstraints(personConstraints);\n      valdr.addConstraints(addressConstraints);\n\n      // when\n      valdr.removeConstraints(['Person', 'Address']);\n\n\n      // then\n      expect(valdr.getConstraints()).toEqual({});\n    });\n\n    it('should broadcast event when constraints change', function () {\n      // given\n      valdr.addConstraints(personConstraints);\n      spyOn($rootScope, '$broadcast');\n\n      // when\n      valdr.removeConstraints('Person');\n\n      // then\n      expect($rootScope.$broadcast).toHaveBeenCalledWith(valdrEvents.revalidate);\n    });\n  });\n\n  describe('validate()', function () {\n\n    it('should not validate if no constraints are defined', function () {\n      // when\n      var validationResult = valdr.validate('Person', 'firstName', 'Hanueli');\n\n      // then\n      expect(validationResult.valid).toBe(true);\n      expect(validationResult.violations).toBeUndefined();\n      expect(validationResult.validationResults).toBeUndefined();\n    });\n\n    it('should validate with correct validator', function () {\n      // given\n      valdr.addConstraints(personConstraints);\n      spyOn(sizeValidator, 'validate').andCallThrough();\n\n      // when\n      var validationResult = valdr.validate('Person', 'firstName', 'Hanueli');\n\n      // then\n      expect(validationResult.valid).toBe(true);\n      expect(validationResult.violations).toBeUndefined();\n      expect(validationResult.validationResults.length).toBe(1);\n      expect(sizeValidator.validate).toHaveBeenCalled();\n    });\n\n    it('should return true if no validator is available for a constraint', function () {\n      // given\n      valdr.addConstraints({\n        'Person': {\n          'firstName': {\n            'ThereIsNoValidatorForThisConstraint': {}\n          }\n        }\n      });\n\n      // when\n      var validationResult = valdr.validate('Person', 'firstName', 'Hanueli');\n\n      // then\n      expect(validationResult.valid).toBe(true);\n    });\n\n    it('should return invalid state and message if validation fails', function () {\n      // given\n      valdr.addConstraints(personConstraints);\n      spyOn(sizeValidator, 'validate').andCallThrough();\n\n      // when\n      var validationResult = valdr.validate('Person', 'firstName', 'Hanueli with a name that is too long');\n\n      // then\n      expect(sizeValidator.validate).toHaveBeenCalled();\n      expect(validationResult.valid).toBe(false);\n      expect(validationResult.violations[0].message).toBe('size');\n      expect(validationResult.violations[0].field).toBe('firstName');\n      expect(validationResult.violations[0].type).toBe('Person');\n      expect(validationResult.violations[0].value).toBe('Hanueli with a name that is too long');\n      expect(validationResult.violations[0].max).toBe(10);\n      expect(validationResult.violations[0].min).toBe(0);\n    });\n\n    it('should return invalid state and message if multiple validations fail', function () {\n      // given\n      valdr.addConstraints({\n        'Person': {\n          'firstName': {\n            'size': {\n              'min': 2,\n              'max': 10,\n              'message': 'size'\n            },\n            'required': {\n              'message': 'required'\n            }\n          }\n        }\n      });\n      spyOn(sizeValidator, 'validate').andCallThrough();\n      spyOn(requiredValidator, 'validate').andCallThrough();\n\n      // when\n      var validationResult = valdr.validate('Person', 'firstName', undefined);\n\n      // then\n      expect(sizeValidator.validate).toHaveBeenCalled();\n      expect(requiredValidator.validate).toHaveBeenCalled();\n      expect(validationResult.valid).toBe(false);\n      expect(validationResult.violations[0].message).toBe('required');\n    });\n\n  });\n\n  describe('setClasses()', function () {\n\n    it('should add the given classes to the valdrClasses and broadcast an event', function () {\n      // given\n      spyOn($rootScope, '$broadcast');\n      var newClass = 'is-valid';\n      expect(valdrClasses.valid).toBe('ng-valid');\n      expect(valdrClasses.invalid).toBe('ng-invalid');\n\n      // when\n      valdr.setClasses({ valid: newClass });\n\n      // then\n      expect($rootScope.$broadcast).toHaveBeenCalledWith(valdrEvents.revalidate);\n      expect(valdrClasses.valid).toBe(newClass);\n      expect(valdrClasses.invalid).toBe('ng-invalid');\n\n      // cleanup to prevent side-effects\n      valdr.setClasses({ valid: 'ng-valid' });\n    });\n\n  });\n});\n\ndescribe('valdrProvider', function () {\n\n  it('should load the constraints via $http', function () {\n    // given\n    var $httpBackend, apiUrl = '/api/validation';\n\n    // when\n    module('valdr');\n    module(function (valdrProvider) {\n      valdrProvider.setConstraintUrl(apiUrl);\n    });\n    inject(function (_$httpBackend_) {\n      $httpBackend = _$httpBackend_;\n      $httpBackend.expect('GET', apiUrl).respond(200, {});\n    });\n\n    /*jshint unused:false */\n    inject(function (valdr) {\n      // injecting the valdr service triggers the loading and therefore the GET to the apiUrl\n      $httpBackend.flush();\n\n      // then\n      $httpBackend.verifyNoOutstandingExpectation();\n      $httpBackend.verifyNoOutstandingRequest();\n    });\n  });\n\n  it('should support to use aliases for constraint names', function () {\n    // given\n    module('valdr');\n    module(function (valdrProvider) {\n      valdrProvider.addConstraints({\n        'Person': {\n          'firstName': {\n            'sizeBetween': {\n              'min': 0,\n              'max': 10\n            },\n            'secondSizeBetween': {\n              'min': 10,\n              'max': 20\n            }\n          }\n        }\n      });\n      valdrProvider.addConstraintAlias('size', 'sizeBetween');\n      valdrProvider.addConstraintAlias('size', 'secondSizeBetween');\n    });\n\n\n    inject(function (valdr, valdrSizeValidator) {\n      // when\n      spyOn(valdrSizeValidator, 'validate').andCallThrough();\n      var validationResult = valdr.validate('Person', 'firstName', 'Hanueli');\n\n      // then\n      expect(validationResult.valid).toBe(false);\n      expect(validationResult.violations).toBeDefined();\n      expect(validationResult.violations.length).toBe(1);\n      expect(validationResult.validationResults.length).toBe(2);\n      expect(valdrSizeValidator.validate).toHaveBeenCalled();\n    });\n  });\n\n  describe('custom validators', function () {\n\n    it('should allow to add custom validators', function () {\n      // given\n      module('valdr');\n\n      module(function ($provide) {\n        $provide.factory('customValidator', function () {\n          return {\n            name: 'custom',\n            validate: function (value) {\n              return value === 'Hanueli';\n            }\n          };\n        });\n      });\n\n      module(function (valdrProvider) {\n        valdrProvider.addValidator('customValidator');\n        valdrProvider.addConstraints({\n          'Person': {\n            'firstName': {\n              'custom': {}\n            }\n          }\n        });\n      });\n\n      inject(function (valdr, customValidator) {\n        // when\n        spyOn(customValidator, 'validate').andCallThrough();\n        var validationResult = valdr.validate('Person', 'firstName', 'Hanueli');\n\n        // then\n        expect(validationResult.valid).toBe(true);\n        expect(validationResult.violations).toBeUndefined();\n        expect(customValidator.validate).toHaveBeenCalled();\n      });\n    });\n\n  });\n\n});"
  },
  {
    "path": "src/core/valdrEnabled-directive.js",
    "content": "angular.module('valdr')\n\n/**\n * This directive allows to dynamically enable and disable the validation with valdr.\n * All form elements in a child node of an element with the 'valdr-enabled' directive will be affected by this.\n *\n * Usage:\n *\n * <div valdr-enabled=\"isValidationEnabled()\">\n *   <input type=\"text\" name=\"name\" ng-model=\"mymodel.field\">\n * </div>\n *\n * If multiple valdr-enabled directives are nested, the one nearest to the validated form element\n * will take precedence.\n */\n  .directive('valdrEnabled', ['valdrEvents', function (valdrEvents) {\n    return  {\n      controller: ['$scope', '$attrs', function($scope, $attrs) {\n        $scope.$watch($attrs.valdrEnabled, function () {\n          $scope.$broadcast(valdrEvents.revalidate);\n        });\n\n        this.isEnabled = function () {\n          var evaluatedExpression = $scope.$eval($attrs.valdrEnabled);\n          return evaluatedExpression === undefined ? true : evaluatedExpression;\n        };\n      }]\n    };\n  }]);\n"
  },
  {
    "path": "src/core/valdrEnabled-directive.spec.js",
    "content": "describe('valdrEnabled directive', function () {\n\n  // VARIABLES\n\n  var $scope, $compile, element, valdr, ngModelController, template,\n    personConstraints = {\n      'Person': {\n        'firstName': {\n          'required': {\n            'message': 'first name is required'\n          }\n        }\n      }\n    };\n\n  // TEST UTILITIES\n\n  function compileValdrEnabledTemplate() {\n    element = $compile(angular.element(template))($scope);\n    $scope.$digest();\n    ngModelController = element.find('input').controller('ngModel');\n  }\n\n  beforeEach(function () {\n    module('valdr');\n  });\n\n  beforeEach(inject(function ($rootScope, _$compile_, _valdr_) {\n    $compile = _$compile_;\n    valdr = _valdr_;\n\n    template =\n      '<form valdr-type=\"Person\" valdr-enabled=\"isValdrEnabled()\">' +\n        '<input type=\"text\" name=\"firstName\" ng-model=\"person.firstName\">' +\n      '</form>';\n\n    $scope = $rootScope.$new();\n\n    $scope.person = { };\n    $scope.valdrEnabled = true;\n    $scope.isValdrEnabled = function () {\n      return $scope.valdrEnabled;\n    };\n\n    valdr.addConstraints(personConstraints);\n  }));\n\n  // TEST\n\n  it('should validate if valdrEnabled is true', function () {\n    // given\n    $scope.valdrEnabled = true;\n\n    // when\n    compileValdrEnabledTemplate();\n\n    // then\n    expect(ngModelController.$valid).toBe(false);\n  });\n\n  it('should not validate if valdrEnabled is false', function () {\n    // given\n    $scope.valdrEnabled = false;\n\n    // when\n    compileValdrEnabledTemplate();\n\n    // then\n    expect(ngModelController.$valid).toBe(true);\n  });\n\n  it('should validate if no expression is provided', function () {\n    // given\n    template =\n      '<form valdr-type=\"Person\" valdr-enabled>' +\n        '<input type=\"text\" name=\"firstName\" ng-model=\"person.firstName\">' +\n      '</form>';\n\n    // when\n    compileValdrEnabledTemplate();\n\n    // then\n    expect(ngModelController.$valid).toBe(false);\n  });\n\n  it('should remove errors when constraints are removed', function () {\n    // given\n    compileValdrEnabledTemplate();\n\n    // when\n    valdr.removeConstraints('Person');\n\n    // then\n    expect(ngModelController.$valid).toBe(true);\n  });\n\n  it('should remove errors when valdr gets disabled', function () {\n    // given\n    compileValdrEnabledTemplate();\n\n    // when\n    $scope.$apply(function () {\n      $scope.valdrEnabled = false;\n    });\n\n    // then\n    expect(ngModelController.$valid).toBe(true);\n  });\n\n});"
  },
  {
    "path": "src/core/valdrFormGroup-directive.js",
    "content": "/**\n * This directive adds the validity state to a form group element surrounding valdr validated input fields.\n * If valdr-messages is loaded, it also adds the validation messages as last element to the element this this\n * directive is applied on.\n */\nvar valdrFormGroupDirectiveDefinition =\n  ['valdrClasses', 'valdrConfig', function (valdrClasses, valdrConfig) {\n    return  {\n      restrict: 'EA',\n      link: function (scope, element) {\n        if (valdrConfig.addFormGroupClass) {\n          element.addClass(valdrClasses.formGroup);\n        }\n      },\n      controller: ['$scope', '$element', function ($scope, $element) {\n\n        var formItems = [],\n          messageElements = {};\n\n        /**\n         * Checks the state of all valdr validated form items below this element.\n         * @returns {Object} an object containing the states of all form items in this form group\n         */\n        var getFormGroupState = function () {\n\n          var formGroupState = {\n            // true if an item in this form group is currently dirty, touched and invalid\n            invalidDirtyTouchedGroup: false,\n            // true if all form items in this group are currently valid\n            valid: true,\n            // contains the validity states of all form items in this group\n            itemStates: []\n          };\n\n          angular.forEach(formItems, function (formItem) {\n            if (formItem.$touched && formItem.$dirty && formItem.$invalid) {\n              formGroupState.invalidDirtyTouchedGroup = true;\n            }\n\n            if (formItem.$invalid) {\n              formGroupState.valid = false;\n            }\n\n            var itemState = {\n              name: formItem.$name,\n              touched: formItem.$touched,\n              dirty: formItem.$dirty,\n              valid: formItem.$valid\n            };\n\n            formGroupState.itemStates.push(itemState);\n          });\n\n          return formGroupState;\n        };\n\n        /**\n         * Updates the classes on this element and the valdr message elements based on the validity states\n         * of the items in this form group.\n         * @param formGroupState the current state of this form group and its items\n         */\n        var updateClasses = function (formGroupState) {\n          // form group state\n          $element.toggleClass(valdrClasses.invalidDirtyTouchedGroup, formGroupState.invalidDirtyTouchedGroup);\n          $element.toggleClass(valdrClasses.valid, formGroupState.valid);\n          $element.toggleClass(valdrClasses.invalid, !formGroupState.valid);\n\n          // valdr message states\n          angular.forEach(formGroupState.itemStates, function (itemState) {\n            var messageElement = messageElements[itemState.name];\n            if (messageElement) {\n              messageElement.toggleClass(valdrClasses.valid, itemState.valid);\n              messageElement.toggleClass(valdrClasses.invalid, !itemState.valid);\n              messageElement.toggleClass(valdrClasses.dirty, itemState.dirty);\n              messageElement.toggleClass(valdrClasses.pristine, !itemState.dirty);\n              messageElement.toggleClass(valdrClasses.touched, itemState.touched);\n              messageElement.toggleClass(valdrClasses.untouched, !itemState.touched);\n            }\n          });\n        };\n\n        $scope.$watch(getFormGroupState, updateClasses, true);\n\n        this.addFormItem = function (ngModelController) {\n          formItems.push(ngModelController);\n        };\n\n        this.removeFormItem = function (ngModelController) {\n          var index = formItems.indexOf(ngModelController);\n          if (index >= 0) {\n            formItems.splice(index, 1);\n          }\n        };\n\n        this.addMessageElement = function (ngModelController, messageElement) {\n          $element.append(messageElement);\n          messageElements[ngModelController.$name] = messageElement;\n        };\n\n        this.removeMessageElement = function (ngModelController) {\n          if (messageElements[ngModelController.$name]) {\n            messageElements[ngModelController.$name].remove();\n            delete messageElements[ngModelController.$name];\n          }\n        };\n\n      }]\n    };\n  }];\n\nangular.module('valdr')\n  .directive('valdrFormGroup', valdrFormGroupDirectiveDefinition);\n"
  },
  {
    "path": "src/core/valdrFormGroup-directive.spec.js",
    "content": "describe('valdrFormGroup directive', function () {\n\n  // VARIABLES\n\n  var $scope, $compile, element, valdr, valdrClasses, valdrConfig, ngModelController,\n    personConstraints = {\n      'Person': {\n        'firstName': {\n          'size': {\n            'min': 0,\n            'max': 10,\n            'message': 'size'\n          }\n        },\n        'lastName': {\n          'size': {\n            'min': 0,\n            'max': 10,\n            'message': 'size'\n          }\n        }\n      }\n    };\n\n  var formGroupTemplate =\n      '<form valdr-type=\"Person\" valdr-form-group>' +\n        '<input type=\"text\" name=\"firstName\" valdr-no-message ng-model=\"person.firstName\">' +\n        '<input type=\"text\" name=\"lastName\" valdr-no-message  ng-model=\"person.lastName\">' +\n      '</form>';\n\n  // TEST UTILITIES\n\n  function compileTemplate(template) {\n    element = $compile(angular.element(template))($scope);\n    $scope.$digest();\n  }\n\n  function compileFormGroupTemplate() {\n    compileTemplate(formGroupTemplate);\n    ngModelController = element.find('input').controller('ngModel');\n  }\n\n  beforeEach(function () {\n    module('valdr');\n  });\n\n  beforeEach(inject(function ($rootScope, _$compile_, _valdr_, _valdrClasses_, _valdrConfig_) {\n    $compile = _$compile_;\n    valdr = _valdr_;\n    valdrClasses = _valdrClasses_;\n    valdrConfig = _valdrConfig_;\n\n    $scope = $rootScope.$new();\n    $scope.person = { };\n    valdr.addConstraints(personConstraints);\n  }));\n\n\n  describe('valdrFormGroup', function () {\n\n    beforeEach(function () {\n      compileFormGroupTemplate();\n    });\n\n    describe('form-group class', function () {\n\n      it ('should add form group class by default', function () {\n        expect(element.hasClass(valdrClasses.formGroup)).toBe(true);\n      });\n\n      it ('should not add form group class if option is disabled in valdrConfig', function () {\n        // given\n        valdrConfig.addFormGroupClass = false;\n\n        // when\n        compileFormGroupTemplate();\n\n        // then\n        expect(element.hasClass(valdrClasses.formGroup)).toBe(false);\n      });\n\n    });\n\n    it('should not set valid and invalidDirtyTouchedGroup classes if all items are valid', function () {\n      expect(element.hasClass(valdrClasses.valid)).toBe(true);\n      expect(element.hasClass(valdrClasses.invalid)).toBe(false);\n      expect(element.hasClass(valdrClasses.invalidDirtyTouchedGroup)).toBe(false);\n    });\n\n    it('should not set invalid class if an item is not valid', function () {\n      // given\n      $scope.person.firstName = 'This name is too long for the constraints.';\n\n      // when\n      $scope.$digest();\n\n      // then\n      expect(element.hasClass(valdrClasses.invalid)).toBe(true);\n      expect(element.hasClass(valdrClasses.valid)).toBe(false);\n      expect(element.hasClass(valdrClasses.invalidDirtyTouchedGroup)).toBe(false);\n    });\n\n    it('should add invalidDirtyTouchedGroup class if an input is dirty, touched and invalid', function () {\n      // given\n      $scope.person.firstName = 'This name is too long for the constraints.';\n      ngModelController.$invalid = true;\n      ngModelController.$dirty = true;\n      ngModelController.$touched = true;\n\n      // when\n      $scope.$digest();\n\n      // then\n      expect(element.hasClass(valdrClasses.invalid)).toBe(true);\n      expect(element.hasClass(valdrClasses.valid)).toBe(false);\n      expect(element.hasClass(valdrClasses.invalidDirtyTouchedGroup)).toBe(true);\n    });\n\n    it('should be valid if no form items are registered', function () {\n      // given\n      var template = '<form valdr-type=\"Person\" valdr-form-group></form>';\n\n      // when\n      compileTemplate(template);\n\n      // then\n      expect(element.hasClass(valdrClasses.valid)).toBe(true);\n      expect(element.hasClass(valdrClasses.invalid)).toBe(false);\n      expect(element.hasClass(valdrClasses.invalidDirtyTouchedGroup)).toBe(false);\n    });\n  });\n\n});"
  },
  {
    "path": "src/core/valdrFormItem-directive.js",
    "content": "/**\n * This controller is used if no valdrEnabled parent directive is available.\n */\nvar nullValdrEnabledController = {\n  isEnabled: function () {\n    return true;\n  }\n};\n\n/**\n * This controller is used if no valdrFormGroup parent directive is available.\n */\nvar nullValdrFormGroupController = {\n  addFormItem: angular.noop,\n  removeFormItem: angular.noop\n};\n\n/**\n * This directive adds validation to all input and select fields as well as to explicitly enabled elements which are\n * bound to an ngModel and are surrounded by a valdrType directive. To prevent adding validation to specific fields,\n * the attribute 'valdr-no-validate' can be added to those fields.\n */\nvar valdrFormItemDirectiveDefinitionFactory = function (restrict) {\n    return ['valdrEvents', 'valdr', 'valdrUtil', function (valdrEvents, valdr, valdrUtil) {\n      return {\n        restrict: restrict,\n        require: ['?^valdrType', '?^ngModel', '?^valdrFormGroup', '?^valdrEnabled'],\n        link: function (scope, element, attrs, controllers) {\n\n          var valdrTypeController = controllers[0],\n            ngModelController = controllers[1],\n            valdrFormGroupController = controllers[2] || nullValdrFormGroupController,\n            valdrEnabled = controllers[3] || nullValdrEnabledController,\n            valdrNoValidate = attrs.valdrNoValidate,\n            fieldName = attrs.name;\n\n          /**\n           * Don't do anything if\n           * - this is an <input> that's not inside of a valdr-type block\n           * - there is no ng-model bound to input\n           * - there is the 'valdr-no-validate' attribute present\n           */\n          if (!valdrTypeController || !ngModelController || angular.isDefined(valdrNoValidate)) {\n            return;\n          }\n\n          valdrFormGroupController.addFormItem(ngModelController);\n\n          if (valdrUtil.isEmpty(fieldName) && valdrEnabled.isEnabled()) {\n            console.warn('Form element with ID \"' + attrs.id + '\" is not bound to a field name.');\n          }\n\n          var updateNgModelController = function (validationResult) {\n\n            if (valdrEnabled.isEnabled()) {\n              var validatorTokens = ['valdr'];\n\n              // set validity state for individual valdr validators\n              angular.forEach(validationResult.validationResults, function (result) {\n                var validatorToken = valdrUtil.validatorNameToToken(result.validator);\n                ngModelController.$setValidity(validatorToken, result.valid);\n                validatorTokens.push(validatorToken);\n              });\n\n              // set overall validity state of this form item\n              ngModelController.$setValidity('valdr', validationResult.valid);\n              ngModelController.valdrViolations = validationResult.violations;\n\n              // remove errors for valdr validators which no longer exist\n              angular.forEach(ngModelController.$error, function (value, validatorToken) {\n                if (validatorTokens.indexOf(validatorToken) === -1 && valdrUtil.startsWith(validatorToken, 'valdr')) {\n                  ngModelController.$setValidity(validatorToken, true);\n                }\n              });\n            } else {\n              angular.forEach(ngModelController.$error, function (value, validatorToken) {\n                if (valdrUtil.startsWith(validatorToken, 'valdr')) {\n                  ngModelController.$setValidity(validatorToken, true);\n                }\n              });\n              ngModelController.valdrViolations = undefined;\n            }\n          };\n\n          var validate = function (modelValue) {\n            var validationResult = valdr.validate(valdrTypeController.getType(), fieldName, modelValue);\n            updateNgModelController(validationResult);\n            return valdrEnabled.isEnabled() ? validationResult.valid : true;\n          };\n\n          ngModelController.$validators.valdr = validate;\n\n          scope.$on(valdrEvents.revalidate, function () {\n            validate(ngModelController.$modelValue);\n          });\n\n          scope.$on('$destroy', function () {\n            valdrFormGroupController.removeFormItem(ngModelController);\n          });\n\n        }\n      };\n    }];\n  },\n  valdrFormItemElementDirectiveDefinition = valdrFormItemDirectiveDefinitionFactory('E'),\n  valdrFormItemAttributeDirectiveDefinition = valdrFormItemDirectiveDefinitionFactory('A');\n\nangular.module('valdr')\n  .directive('input', valdrFormItemElementDirectiveDefinition)\n  .directive('select', valdrFormItemElementDirectiveDefinition)\n  .directive('textarea', valdrFormItemElementDirectiveDefinition)\n  .directive('enableValdrValidation', valdrFormItemAttributeDirectiveDefinition);\n"
  },
  {
    "path": "src/core/valdrFormItem-directive.spec.js",
    "content": "describe('valdrFormItem directive', function () {\n\n  // VARIABLES\n\n  var $scope, $compile, element, valdr, valdrEvents, valdrClasses, ngModelController,\n    violations = ['violationsArray'],\n    validationResults = [{ validator: 'required', valid: true }];\n\n  var inputTemplate =\n    '<form name=\"demoForm\">' +\n      '<div valdr-type=\"TestClass\">' +\n        '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\">' +\n      '</div>' +\n    '</form>';\n\n  var selectTemplate =\n    '<form name=\"demoForm\">' +\n      '<div valdr-type=\"TestClass\">' +\n        '<select name=\"fieldName\" ng-model=\"myObject.field\">' +\n          '<option value></option>' +\n          '<option value=\"1\">First</option>' +\n          '<option value=\"2\">Second</option>' +\n        '</select>' +\n      '</div>' +\n    '</form>';\n\n  var textareaTemplate =\n      '<form name=\"demoForm\">' +\n        '<div valdr-type=\"TestClass\">' +\n          '<textarea name=\"fieldName\" ng-model=\"myObject.field\">' +\n          '</textarea>' +\n        '</div>' +\n      '</form>';\n\n  var inputWidgetTemplate =\n    '<form name=\"demoForm\">' +\n      '<div valdr-type=\"TestClass\">' +\n        '<section name=\"fieldName\" ng-model=\"myObject.field\" enable-valdr-validation>' +\n        '</section>' +\n      '</div>' +\n    '</form>';\n\n  // TEST UTILITIES\n\n  function compileTemplate(template) {\n    element = $compile(angular.element(template))($scope);\n    $scope.$digest();\n  }\n\n  function compileInputTemplate() {\n    compileTemplate(inputTemplate);\n    ngModelController = element.find('input').controller('ngModel');\n  }\n\n  // COMMON SETUP\n\n  beforeEach(function () {\n    module('valdr');\n\n    /**\n     * Mock the valdr to always return 'true' when the value equals the string 'valid'.\n     */\n    module(function ($provide) {\n      $provide.value('valdr', {\n        validate: function (typeName, fieldName, value) {\n          return {\n            valid: value === 'valid',\n            violations: violations,\n            validationResults: validationResults\n          };\n        }\n      });\n    });\n  });\n\n  beforeEach(inject(function ($rootScope, _$compile_, _valdr_, _valdrEvents_, _valdrClasses_) {\n    $compile = _$compile_;\n    $scope = $rootScope.$new();\n    $scope.myObject = { field: 'fieldValue' };\n    valdr = _valdr_;\n    valdrEvents = _valdrEvents_;\n    valdrClasses = _valdrClasses_;\n  }));\n\n  // COMMON TESTS\n\n  function runFormItemCommonTests() {\n    it('should set the validity to false on ngModelController if validation fails', function () {\n      // when\n      $scope.$apply(function () {\n        $scope.myObject.field = 'invalid';\n      });\n\n      // then\n      expect(ngModelController.$valid).toBe(false);\n      expect(ngModelController.valdrViolations).toBe(violations);\n      expect(ngModelController.$validators.valdr).toBeDefined();\n    });\n\n    it('should set the validity to true on ngModelController if validation is ok', function () {\n      // when\n      $scope.$apply(function () {\n        $scope.myObject.field = 'valid';\n      });\n\n      // then\n      expect(ngModelController.$valid).toBe(true);\n      expect(ngModelController.valdrViolations).toBe(violations);\n    });\n\n    it('should register in valdrFormGroup', function () {\n      // given\n      var formGroupTemplate =\n        '<form name=\"demoForm\" valdr-type=\"TestClass\" valdr-form-group>' +\n            '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\">' +\n        '</form>';\n      compileTemplate(formGroupTemplate);\n\n      // when\n      $scope.$apply(function () {\n        $scope.myObject.field = 'invalid';\n      });\n\n      // then\n      expect(element.hasClass(valdrClasses.invalid)).toBe(true);\n    });\n\n    it('should unregister from valdrFormGroup on $destroy', function () {\n      // given\n      var formGroupTemplate =\n        '<form name=\"demoForm\" valdr-type=\"TestClass\" valdr-form-group>' +\n          '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\">' +\n        '</form>';\n      compileTemplate(formGroupTemplate);\n      $scope.$apply(function () {\n        $scope.myObject.field = 'invalid';\n      });\n\n      // when\n      $scope.$broadcast('$destroy');\n      $scope.$digest();\n\n      // then\n      expect(element.hasClass(valdrClasses.invalid)).toBe(false);\n    });\n\n    it('should handle constraint changed events', function () {\n      // given\n      spyOn(valdr, 'validate').andCallThrough();\n      ngModelController.$viewValue = 'viewValue';\n\n      // when\n      $scope.$broadcast(valdrEvents.revalidate);\n\n      // then\n      expect(valdr.validate).toHaveBeenCalledWith(jasmine.any(String), 'fieldName', ngModelController.$modelValue);\n    });\n  }\n\n  describe('on input fields', function () {\n\n    beforeEach(function () {\n      compileInputTemplate();\n    });\n\n    runFormItemCommonTests();\n\n    it('should log warning if no field name is provided on the input', function () {\n      // given\n      spyOn(console, 'warn');\n      var invalidInput =\n        '<form name=\"demoForm\">' +\n          '<div valdr-type=\"TestClass\">' +\n            '<input type=\"text\" ng-model=\"myObject.field\">' +\n          '</div>' +\n        '</form>';\n\n      // when\n      $compile(angular.element(invalidInput))($scope);\n\n      // then\n      expect(console.warn).toHaveBeenCalledWith('Form element with ID \"undefined\" is not bound to a field name.');\n    });\n\n    it('should NOT log warning if no field name is provided on the input but valdr is disabled', function () {\n      // given\n      spyOn(console, 'warn');\n      var invalidInput =\n        '<form name=\"demoForm\" valdr-enabled=\"false\">' +\n        '  <div valdr-type=\"TestClass\">' +\n        '    <input type=\"text\" ng-model=\"myObject.field\">' +\n        '  </div>' +\n        '</form>';\n\n      // when\n      compileTemplate(invalidInput);\n\n      // then\n      expect(console.warn).not.toHaveBeenCalled();\n    });\n\n    it('should NOT use valdr validation if valdr-no-validate is set', function () {\n      // given\n      var noValdrValidationInput =\n        '<form name=\"demoForm\">' +\n          '<div valdr-type=\"TestClass\">' +\n            '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\" valdr-no-validate>' +\n          '</div>' +\n        '</form>';\n\n      // when\n      compileTemplate(noValdrValidationInput);\n      ngModelController = element.find('input').controller('ngModel');\n\n      // then\n      expect(ngModelController.$validators.valdr).toBeUndefined();\n    });\n  });\n\n  describe('on select elements', function () {\n\n    beforeEach(function () {\n      compileTemplate(selectTemplate);\n      ngModelController = element.find('select').controller('ngModel');\n    });\n\n    runFormItemCommonTests();\n\n  });\n\n\n  describe('on textarea elements', function () {\n\n    beforeEach(function () {\n      compileTemplate(textareaTemplate);\n      ngModelController = element.find('textarea').controller('ngModel');\n    });\n\n    runFormItemCommonTests();\n\n  });\n\n  describe('on explicitly enabled elements', function () {\n\n    beforeEach(function () {\n      compileTemplate(inputWidgetTemplate);\n      ngModelController = element.find('section').controller('ngModel');\n    });\n\n    runFormItemCommonTests();\n\n  });\n\n});\n"
  },
  {
    "path": "src/core/valdrType-directive.js",
    "content": "angular.module('valdr')\n\n/**\n * The valdrType directive defines the type of the model to be validated.\n * The directive exposes the type through the controller to allow access to it by wrapped directives.\n */\n  .directive('valdrType', function () {\n    return  {\n      priority: 1,\n      controller: ['$attrs', function ($attrs) {\n\n        this.getType = function () {\n          return $attrs.valdrType;\n        };\n\n      }]\n    };\n  });\n"
  },
  {
    "path": "src/core/valdrType-directive.spec.js",
    "content": "describe('valdrType directive', function () {\n\n  var $scope, $compile, element, FormTypeController;\n\n  var compileTemplate = function () {\n    var element = $compile(angular.element('<div valdr-type=\"TestClass\"></div>'))($scope);\n    $scope.$digest();\n    return element;\n  };\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function ($rootScope, $controller, _$compile_) {\n    $compile = _$compile_;\n    $scope = $rootScope.$new();\n    element = compileTemplate();\n    FormTypeController = element.controller('valdrType');\n  }));\n\n  it('should read the type from the attribute', function () {\n    expect(FormTypeController.getType()).toBe('TestClass');\n  });\n\n  it('should allow to nest the directive', function () {\n    // given\n    var element = $compile(angular.element(\n      '<div valdr-type=\"TestClass\">' +\n        '<span valdr-type=\"NestedClass\"></span>' +\n        '</div>'))($scope);\n\n    // when\n    var rootController = element.controller('valdrType');\n    var nestedController = element.find('span').controller('valdrType');\n\n    // then\n    expect(rootController.getType()).toBe('TestClass');\n    expect(nestedController.getType()).toBe('NestedClass');\n  });\n\n});\n"
  },
  {
    "path": "src/core/valdrUtil-service.js",
    "content": "angular.module('valdr')\n\n/**\n * Exposes utility functions used in validators and valdr core.\n */\n  .factory('valdrUtil', [function () {\n\n    var substringAfterDot = function (string) {\n      if (string.lastIndexOf('.') === -1) {\n        return string;\n      } else {\n        return string.substring(string.lastIndexOf('.') + 1, string.length);\n      }\n    };\n\n    var SLUG_CASE_REGEXP = /[A-Z]/g;\n    var slugCase = function (string) {\n      return string.replace(SLUG_CASE_REGEXP, function(letter, pos) {\n        return (pos ? '-' : '') + letter.toLowerCase();\n      });\n    };\n\n    /**\n     * Converts the given validator name to a validation token. Uses the last part of the validator name after the\n     * dot (if present) and converts camel case to slug case (fooBar -> foo-bar).\n     * @param validatorName the validator name\n     * @returns {string} the validation token\n     */\n    var validatorNameToToken = function (validatorName) {\n      if (angular.isString(validatorName)) {\n        var name = substringAfterDot(validatorName);\n        name = slugCase(name);\n        return 'valdr-' + name;\n      } else {\n        return validatorName;\n      }\n    };\n\n    return {\n      validatorNameToToken: validatorNameToToken,\n\n      isNaN: function (value) {\n        // `NaN` as a primitive is the only value that is not equal to itself\n        // (perform the [[Class]] check first to avoid errors with some host objects in IE)\n        return this.isNumber(value) && value !== +value;\n      },\n\n      isNumber: function (value) {\n        var type = typeof value;\n        return type === 'number' ||\n          value && type === 'object' && Object.prototype.toString.call(value) === '[object Number]' || false;\n      },\n\n      has: function (object, key) {\n        return object ? Object.prototype.hasOwnProperty.call(object, key) : false;\n      },\n\n      /**\n       * @param value the value\n       * @returns {boolean} true if the given value is not null, not undefined, not an empty string, NaN returns false\n       */\n      notEmpty: function (value) {\n        if (this.isNaN(value)) {\n          return false;\n        }\n        if (angular.isArray(value) && value.length === 0){\n          return false;\n        }\n        return angular.isDefined(value) && value !== '' && value !== null;\n      },\n\n      /**\n       * @param value the value to validate\n       * @returns {boolean} true if the given value is null, undefined, an empty string, NaN returns false\n       */\n      isEmpty: function (value) {\n        if (this.isNaN(value)) {\n          return false;\n        }\n        return !this.notEmpty(value);\n      },\n\n      /**\n       * Checks if a string value starts with a given prefix.\n       *\n       * @param value the value\n       * @param prefix the prefix\n       * @returns {boolean} true if the given value starts with the given prefix.\n       */\n      startsWith: function (value, prefix) {\n        return angular.isString(value)  &&\n          angular.isString(prefix) &&\n          value.lastIndexOf(prefix, 0) === 0;\n      }\n    };\n  }])\n;\n"
  },
  {
    "path": "src/core/valdrUtil-service.spec.js",
    "content": "describe('valdrUtil', function () {\n\n  var valdrUtil;\n\n  beforeEach(module('valdr'));\n  beforeEach(inject(function (_valdrUtil_) {\n    valdrUtil = _valdrUtil_;\n  }));\n\n  describe('validatorNameToToken()', function () {\n\n    it('should convert camel case to slug case and prepend with valdr', function () {\n      expect(valdrUtil.validatorNameToToken(undefined)).toBe(undefined);\n      expect(valdrUtil.validatorNameToToken('nocamel')).toBe('valdr-nocamel');\n      expect(valdrUtil.validatorNameToToken('camelCase')).toBe('valdr-camel-case');\n      expect(valdrUtil.validatorNameToToken('CapitalCamelCase')).toBe('valdr-capital-camel-case');\n    });\n\n    it('should convert remove everything before the last dot and convert to slug case', function () {\n      expect(valdrUtil.validatorNameToToken('bla.nocamel')).toBe('valdr-nocamel');\n      expect(valdrUtil.validatorNameToToken('bla.camelCase')).toBe('valdr-camel-case');\n      expect(valdrUtil.validatorNameToToken('bla.CapitalCamelCase')).toBe('valdr-capital-camel-case');\n    });\n\n  });\n\n  describe('isNaN()', function () {\n\n    it('should provide isNaN function', inject(function (valdrUtil) {\n      expect(valdrUtil.isNaN).toBeDefined();\n      expect(typeof valdrUtil.isNaN).toBe('function');\n    }));\n\n    it('should check if input is NaN', function () {\n      expect(valdrUtil.isNaN(NaN)).toBe(true);\n      expect(valdrUtil.isNaN('string')).toBe(false);\n      expect(valdrUtil.isNaN(0)).toBe(false);\n    });\n\n  });\n\n  describe('isNumber()', function () {\n\n    it('should provide isNumber function', inject(function (valdrUtil) {\n      expect(valdrUtil.isNumber).toBeDefined();\n      expect(typeof valdrUtil.isNumber).toBe('function');\n    }));\n\n    it('should check if input is a number', function () {\n      expect(valdrUtil.isNumber(NaN)).toBe(true);\n      expect(valdrUtil.isNumber(0)).toBe(true);\n      expect(valdrUtil.isNumber('string')).toBe(false);\n      expect(valdrUtil.isNumber(undefined)).toBe(false);\n      expect(valdrUtil.isNumber(null)).toBe(false);\n    });\n\n  });\n\n  describe('has()', function () {\n\n    it('should provide has function', inject(function (valdrUtil) {\n      expect(valdrUtil.has).toBeDefined();\n      expect(typeof valdrUtil.has).toBe('function');\n    }));\n\n    it('should check if object has property', function () {\n      expect(valdrUtil.has({foo: 'a'}, 'foo')).toBe(true);\n      expect(valdrUtil.has({foo: undefined}, 'foo')).toBe(true);\n      expect(valdrUtil.has({}, 'foo')).toBe(false);\n      expect(valdrUtil.has(undefined, 'foo')).toBe(false);\n    });\n\n  });\n\n  describe('notEmpty()/isEmpty()', function () {\n\n    it('should validate strings', function () {\n      expect(valdrUtil.notEmpty('string')).toBe(true);\n      expect(valdrUtil.isEmpty('string')).toBe(false);\n    });\n\n    it('should validate null value', function () {\n      expect(valdrUtil.notEmpty(null)).toBe(false);\n      expect(valdrUtil.isEmpty(null)).toBe(true);\n      expect(valdrUtil.notEmpty('null')).toBe(true);\n      expect(valdrUtil.isEmpty('null')).toBe(false);\n    });\n\n    it('should validate undefined value', function () {\n      expect(valdrUtil.notEmpty(undefined)).toBe(false);\n      expect(valdrUtil.isEmpty(undefined)).toBe(true);\n    });\n\n    it('should validate NaN value', function () {\n      // NaN obviously is not a number but we don't know what it is, hence we cannot tell whether it's empty or not\n      expect(valdrUtil.notEmpty(NaN)).toBe(false);\n      expect(valdrUtil.isEmpty(NaN)).toBe(false);\n    });\n\n    it('should validate empty string', function () {\n      expect(valdrUtil.notEmpty('')).toBe(false);\n      expect(valdrUtil.isEmpty('')).toBe(true);\n    });\n\n    it('should validate arrays', function () {\n      expect(valdrUtil.notEmpty(['Apple', 'Banana'])).toBe(true);\n      expect(valdrUtil.isEmpty(['Apple', 'Banana'])).toBe(false);\n      expect(valdrUtil.isEmpty([])).toBe(true);\n      expect(valdrUtil.notEmpty([])).toBe(false);\n    });\n\n  });\n\n  describe('startsWith()', function () {\n\n    it ('should determine if a string starts with the given prefix', function () {\n      expect(valdrUtil.startsWith('myString', 'my')).toBe(true);\n      expect(valdrUtil.startsWith('string', 'string')).toBe(true);\n      expect(valdrUtil.startsWith('', '')).toBe(true);\n      expect(valdrUtil.startsWith('value', '')).toBe(true);\n    });\n\n    it('should return false if a string does not start with the specified prefix', function () {\n      expect(valdrUtil.startsWith('', 'prefix')).toBe(false);\n      expect(valdrUtil.startsWith('someThing', 'something')).toBe(false);\n      expect(valdrUtil.startsWith(undefined, 'prefix')).toBe(false);\n      expect(valdrUtil.startsWith(undefined, undefined)).toBe(false);\n      expect(valdrUtil.startsWith('value', undefined)).toBe(false);\n    });\n\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/digitsValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrDigitsValidator', ['valdrUtil', function (valdrUtil) {\n\n    // matches everything except digits and '.' as decimal separator\n    var regexp = new RegExp('[^.\\\\d]', 'g');\n\n    /**\n     * By converting to number and back to string using toString(), we make sure that '.' is used as decimal separator\n     * and not the locale specific decimal separator.\n     * As we already checked for NaN at this point, we can do this safely.\n     */\n    var toStringWithoutThousandSeparators = function (value) {\n      return Number(value).toString().replace(regexp, '');\n    };\n\n    var isNotLongerThan = function (valueAsString, maxLengthConstraint) {\n      return !valueAsString ? true : valueAsString.length <= maxLengthConstraint;\n    };\n\n    var doValidate = function (value, constraint) {\n      var integerConstraint = constraint.integer,\n        fractionConstraint = constraint.fraction,\n        cleanValueAsString, integerAndFraction;\n\n      cleanValueAsString = toStringWithoutThousandSeparators(value);\n      integerAndFraction = cleanValueAsString.split('.');\n\n      return isNotLongerThan(integerAndFraction[0], integerConstraint) &&\n        isNotLongerThan(integerAndFraction[1], fractionConstraint);\n    };\n\n    return {\n      name: 'digits',\n\n      /**\n       * Checks if the value is a number within accepted range.\n       *\n       * @param value the value to validate\n       * @param constraint the validation constraint, it is expected to have integer and fraction properties (maximum\n       *                   number of integral/fractional digits accepted for this number)\n       * @returns {boolean} true if valid\n       */\n      validate: function (value, constraint) {\n\n        if (valdrUtil.isEmpty(value)) {\n          return true;\n        }\n        if (valdrUtil.isNaN(Number(value))) {\n          return false;\n        }\n\n        return doValidate(value, constraint);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/digitsValidator.spec.js",
    "content": "describe('valdrDigitsValidator', function () {\n\n  var digitsValidator, constraint;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrDigitsValidator) {\n    digitsValidator = valdrDigitsValidator;\n    constraint = { integer: '4', fraction: '2' };\n  }));\n\n  it('should be named \"digits\"', function () {\n    expect(digitsValidator.name).toBe('digits');\n  });\n\n  it('should return true for empty, null, and undefined', function () {\n    expect(digitsValidator.validate('', constraint)).toBe(true);\n    expect(digitsValidator.validate(null, constraint)).toBe(true);\n    expect(digitsValidator.validate(undefined, constraint)).toBe(true);\n  });\n\n  it('should return false for NaN', function () {\n    expect(digitsValidator.validate(NaN, constraint)).toBe(false);\n  });\n\n  it('should return true for valid integers', function () {\n    expect(digitsValidator.validate('10', constraint)).toBe(true);\n    expect(digitsValidator.validate(10, constraint)).toBe(true);\n    expect(digitsValidator.validate(1000, constraint)).toBe(true);\n    expect(digitsValidator.validate(-1000, constraint)).toBe(true);\n    expect(digitsValidator.validate('10.02', constraint)).toBe(true);\n    expect(digitsValidator.validate(10.02, constraint)).toBe(true);\n    expect(digitsValidator.validate(-10.02, constraint)).toBe(true);\n    expect(digitsValidator.validate(9999.99, constraint)).toBe(true);\n    expect(digitsValidator.validate(-9999.99, constraint)).toBe(true);\n  });\n\n  it('should return false for invalid numbers and strings', function () {\n    expect(digitsValidator.validate(10.001, constraint)).toBe(false);\n    expect(digitsValidator.validate('10001', constraint)).toBe(false);\n    expect(digitsValidator.validate('10.001', constraint)).toBe(false);\n    expect(digitsValidator.validate(1000.001, constraint)).toBe(false);\n    expect(digitsValidator.validate('string', constraint)).toBe(false);\n    expect(digitsValidator.validate('number', constraint)).toBe(false);\n    expect(digitsValidator.validate('47:11', constraint)).toBe(false);\n    expect(digitsValidator.validate('47;11', constraint)).toBe(false);\n    expect(digitsValidator.validate('47\\'11', constraint)).toBe(false);\n  });\n\n  it('should validate correctly with fraction > 4', function() {\n    constraint.fraction = 4;\n    expect(digitsValidator.validate(1000.00001, constraint)).toBe(false);\n    expect(digitsValidator.validate(1000.0001, constraint)).toBe(true);\n  });\n\n  it('should not choke on integer:1 conditions', function () {\n    constraint.integer = 1;\n    expect(digitsValidator.validate('10', constraint)).toBe(false);\n    expect(digitsValidator.validate(10.0, constraint)).toBe(false);\n    expect(digitsValidator.validate(0.1, constraint)).toBe(true);\n    expect(digitsValidator.validate(0.11, constraint)).toBe(true);\n    expect(digitsValidator.validate(0.111, constraint)).toBe(false);\n  });\n\n  it('should not choke on fraction:0 conditions', function () {\n    constraint.fraction = 1;\n    expect(digitsValidator.validate('10', constraint)).toBe(true);\n    expect(digitsValidator.validate(10.0, constraint)).toBe(true);\n    expect(digitsValidator.validate(10, constraint)).toBe(true);\n    expect(digitsValidator.validate(0, constraint)).toBe(true);\n    expect(digitsValidator.validate(0.11, constraint)).toBe(false);\n    expect(digitsValidator.validate(0.111, constraint)).toBe(false);\n  });\n});\n"
  },
  {
    "path": "src/core/validators/emailValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrEmailValidator', ['valdrUtil', function (valdrUtil) {\n\n    // the e-mail pattern used in angular.js\n    var EMAIL_REGEXP = /^[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;\n\n    return {\n      name: 'email',\n\n      /**\n       * Checks if the value is a valid email address.\n       *\n       * @param value the value to validate\n       * @returns {boolean} true if valid\n       */\n      validate: function (value) {\n        return valdrUtil.isEmpty(value) || EMAIL_REGEXP.test(value);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/emailValidator.spec.js",
    "content": "describe('valdrEmailValidator', function () {\n\n  var emailValidator;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrEmailValidator) {\n    emailValidator = valdrEmailValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(emailValidator.name).toBe('email');\n  });\n\n  it('should return true for empty values', function () {\n    expect(emailValidator.validate('')).toBe(true);\n    expect(emailValidator.validate(undefined)).toBe(true);\n  });\n\n  it('should return true for valid email addresses', function () {\n    expect(emailValidator.validate('hanueli@mountains.ch')).toBe(true);\n    expect(emailValidator.validate('valdr.welds@anything.com')).toBe(true);\n    expect(emailValidator.validate('hanueli@asdf')).toBe(true);\n    expect(emailValidator.validate('hanueli@192.168.1.1')).toBe(true);\n    expect(emailValidator.validate('a@3b.c')).toBe(true);\n    expect(emailValidator.validate('a@b')).toBe(true);\n  });\n\n  it('should return false for invalid email addresses', function () {\n    expect(emailValidator.validate('hanueli@')).toBe(false);\n    expect(emailValidator.validate('hanueli@@gmail.com')).toBe(false);\n    expect(emailValidator.validate('hanueli@gm ail.com')).toBe(false);\n    expect(emailValidator.validate('hanueli@gmail..com')).toBe(false);\n    expect(emailValidator.validate('hanueli@gmail.com.')).toBe(false);\n    expect(emailValidator.validate('@anything.com')).toBe(false);\n    expect(emailValidator.validate('...')).toBe(false);\n    expect(emailValidator.validate('.@.')).toBe(false);\n    expect(emailValidator.validate(' aaa.@. ')).toBe(false);\n    expect(emailValidator.validate('a@-b.c')).toBe(false);\n    expect(emailValidator.validate('a@b-.c')).toBe(false);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/futureAndPastSharedValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('futureAndPastSharedValidator', ['valdrUtil', function (valdrUtil) {\n\n    var someAlternativeDateFormats = ['D-M-YYYY', 'D.M.YYYY', 'D/M/YYYY', 'D. M. YYYY', 'YYYY.M.D'];\n\n    return {\n      validate: function (value, comparison) {\n        var now = moment(), valueAsMoment;\n\n        if (valdrUtil.isEmpty(value)) {\n          return true;\n        }\n\n        valueAsMoment = moment(value);\n\n        for (var i = 0; i < someAlternativeDateFormats.length && !valueAsMoment.isValid(); i++) {\n          valueAsMoment = moment(value, someAlternativeDateFormats[i], true);\n        }\n\n        return valueAsMoment.isValid() && comparison(valueAsMoment, now);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/futureValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrFutureValidator', ['futureAndPastSharedValidator', function (futureAndPastSharedValidator) {\n\n    return {\n      name: 'future',\n\n      /**\n       * Checks if the value is a date in the future.\n       *\n       * @param value the value to validate\n       * @returns {boolean} true if empty, null, undefined or a date in the future, false otherwise\n       */\n      validate: function (value) {\n\n        return futureAndPastSharedValidator.validate(value, function (valueAsMoment, now) {\n          return valueAsMoment.isAfter(now);\n        });\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/futureValidator.spec.js",
    "content": "describe('valdrFutureValidator', function () {\n\n  var futureValidator;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrFutureValidator) {\n    futureValidator = valdrFutureValidator;\n  }));\n\n  it('should be named \"future\"', function () {\n    expect(futureValidator.name).toBe('future');\n  });\n\n  it('should return true for empty values', function () {\n    expect(futureValidator.validate('')).toBe(true);\n    expect(futureValidator.validate(null)).toBe(true);\n    expect(futureValidator.validate(undefined)).toBe(true);\n  });\n\n  it('should return false for NaN', function () {\n    expect(futureValidator.validate(NaN)).toBe(false);\n  });\n\n  it('should return false for non-dates', function () {\n    expect(futureValidator.validate(' ')).toBe(false);\n    expect(futureValidator.validate('foo')).toBe(false);\n    expect(futureValidator.validate('_1.1.2014')).toBe(false);\n    expect(futureValidator.validate('31.2.2014')).toBe(false);\n    expect(futureValidator.validate('31:1:2014')).toBe(false);\n  });\n\n  it('should return false for dates in the past', function () {\n    expect(futureValidator.validate('1.1.1900')).toBe(false);\n    expect(futureValidator.validate('01.01.1900')).toBe(false);\n    expect(futureValidator.validate('1. 1. 1900')).toBe(false);\n    expect(futureValidator.validate('01. 01. 1900')).toBe(false);\n    expect(futureValidator.validate('1-1-1900')).toBe(false);\n    expect(futureValidator.validate('01-01-1900')).toBe(false);\n    expect(futureValidator.validate('1/1/1900')).toBe(false);\n    expect(futureValidator.validate('01/01/1900')).toBe(false);\n    expect(futureValidator.validate('1900.1.1')).toBe(false);\n    expect(futureValidator.validate('1900.01.01')).toBe(false);\n    expect(futureValidator.validate('2000/12/31')).toBe(false);\n    expect(futureValidator.validate('2000-12-31')).toBe(false);\n    expect(futureValidator.validate(moment().subtract(1, 'seconds'))).toBe(false);\n  });\n\n  it('should return true for dates in the future', function () {\n    expect(futureValidator.validate('1.1.2900')).toBe(true);\n    expect(futureValidator.validate('2030/12/31')).toBe(true);\n    expect(futureValidator.validate('2030-12-31')).toBe(true);\n    expect(futureValidator.validate(moment().add(10, 'seconds'))).toBe(true);\n  });\n});\n"
  },
  {
    "path": "src/core/validators/hibernateEmailValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrHibernateEmailValidator', ['valdrUtil', function (valdrUtil) {\n    var ATOM = '[a-z0-9!#$%&\\'*+/=?^_`{|}~-]';\n    var DOMAIN = '^' + ATOM + '+(\\\\.' + ATOM + '+)*$';\n    var IP_DOMAIN = '^\\\\[[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\]$';\n\n    var localPattern = new RegExp('^' + ATOM + '+(\\\\.' + ATOM + '+)*$', 'i');\n    var domainPattern = new RegExp(DOMAIN + '|' + IP_DOMAIN, 'i');\n\n    return {\n      name: 'hibernateEmail',\n\n      /**\n       * Checks if the value is a valid email address using the same patterns as Hibernate uses in its bean validation\n       * implementation.\n       *\n       * @param value the value to validate\n       * @returns {boolean} true if valid\n       */\n      validate: function (value) {\n        if (valdrUtil.isEmpty(value)) {\n          return true;\n        }\n\n        // split email at '@' and consider local and domain part separately\n        var emailParts = value.split('@');\n        if (emailParts.length !== 2) {\n          return false;\n        }\n\n        if (!localPattern.test(emailParts[0])) {\n          return false;\n        }\n\n        return domainPattern.test(emailParts[1]);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/hibernateEmailValidator.spec.js",
    "content": "describe('valdrEmailValidator', function () {\n\n  var hibernateEmailValidator;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrHibernateEmailValidator) {\n    hibernateEmailValidator = valdrHibernateEmailValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(hibernateEmailValidator.name).toBe('hibernateEmail');\n  });\n\n  it('should return true for empty values', function () {\n    expect(hibernateEmailValidator.validate('')).toBe(true);\n    expect(hibernateEmailValidator.validate(undefined)).toBe(true);\n  });\n\n  it('should return true for valid email addresses', function () {\n    expect(hibernateEmailValidator.validate('hanueli@mountains.ch')).toBe(true);\n    expect(hibernateEmailValidator.validate('valdr.welds@anything.com')).toBe(true);\n    expect(hibernateEmailValidator.validate('hanueli@asdf')).toBe(true);\n    expect(hibernateEmailValidator.validate('hanueli@192.168.1.1')).toBe(true);\n  });\n\n  it('should return false for invalid email addresses', function () {\n    expect(hibernateEmailValidator.validate('hanueli@')).toBe(false);\n    expect(hibernateEmailValidator.validate('hanueli@@gmail.com')).toBe(false);\n    expect(hibernateEmailValidator.validate('hanueli@gm ail.com')).toBe(false);\n    expect(hibernateEmailValidator.validate('hanueli@gmail..com')).toBe(false);\n    expect(hibernateEmailValidator.validate('hanueli@gmail.com.')).toBe(false);\n    expect(hibernateEmailValidator.validate('@anything.com')).toBe(false);\n    expect(hibernateEmailValidator.validate('...')).toBe(false);\n    expect(hibernateEmailValidator.validate('.@.')).toBe(false);\n    expect(hibernateEmailValidator.validate(' aaa.@. ')).toBe(false);\n    expect(hibernateEmailValidator.validate('hanueli.@gmail.com')).toBe(false);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/hibernateUrlValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrHibernateUrlValidator', ['valdrUrlValidator', function (valdrUrlValidator) {\n\n    return {\n      name: 'hibernateUrl',\n\n      /**\n       * Checks if the value is a valid URL according to the internal URL validator. It'll also ignore the Hibernate\n       * properties protocol, host, and port. See https://github.com/netceteragroup/valdr/issues/27 for the rational\n       * behind this implementation.\n       *\n       * @param value the value to validate\n       * @returns {boolean} true if valid\n       */\n      validate: function (value) {\n        return valdrUrlValidator.validate(value);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/hibernateUrlValidator.spec.js",
    "content": "describe('valdrHibernateUrlValidator', function () {\n\n  var urlValidator;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrHibernateUrlValidator) {\n    urlValidator = valdrHibernateUrlValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(urlValidator.name).toBe('hibernateUrl');\n  });\n\n  it('should return true for empty values', function () {\n    expect(urlValidator.validate('')).toBe(true);\n    expect(urlValidator.validate(undefined)).toBe(true);\n  });\n\n  it('should return true for valid url', function () {\n    // some trivial tests\n    expect(urlValidator.validate('http://www.google.ch')).toBe(true);\n    expect(urlValidator.validate('http://server:123/path')).toBe(true);\n    // some tests from http://djpowell.net/atomrdf/0.1/files/uritest.xml\n    expect(urlValidator.validate('http://a/b/c/d;p?q#s')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/g?y#s')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/g..')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/d;p?y')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/g;x=1/y')).toBe(true);\n  });\n\n  it('should return false for invalid url', function () {\n    expect(urlValidator.validate('a@B.c')).toBe(false);\n    expect(urlValidator.validate('hanueli')).toBe(false);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/maxLengthValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrMaxLengthValidator', ['valdrUtil', function (valdrUtil) {\n    return {\n      name: 'maxLength',\n\n      /**\n       * Checks if the value is a string and if it's at most 'constraint.number' of characters long.\n       *\n       * @param value the value to validate\n       * @param constraint with property 'number'\n       * @returns {boolean} true if valid\n       */\n      validate: function (value, constraint) {\n        var maxLength = constraint.number;\n\n        if (valdrUtil.isEmpty(value)) {\n          return true;\n        }\n\n        if (typeof value === 'string') {\n          return value.length <= maxLength;\n        } else {\n          return false;\n        }\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/maxLengthValidator.spec.js",
    "content": "describe('valdrMaxLengthValidator', function () {\n\n  var maxLengthValidator, constraint = {\n    number: 5,\n    message: 'message'\n  };\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrMaxLengthValidator) {\n    maxLengthValidator = valdrMaxLengthValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(maxLengthValidator.name).toBe('maxLength');\n  });\n\n  it('should return true if value is valid', function () {\n    // given\n    var value = 'a';\n\n    // when\n    var valid = maxLengthValidator.validate(value, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should return false if string exceeds maxLength', function () {\n    // given\n    var value = 'super long string that exceeds maxLength';\n\n    // when\n    var valid = maxLengthValidator.validate(value, constraint);\n\n    // then\n    expect(valid).toBe(false);\n  });\n\n  it('should be valid if value is undefined', function () {\n    // given\n\n    // when\n    var valid = maxLengthValidator.validate(undefined, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should be invalid if value is number', function () {\n    // given\n    constraint.number = 2;\n\n    // when\n    var valid = maxLengthValidator.validate(123, constraint);\n\n    // then\n    expect(valid).toBe(false);\n  });\n\n  it('should be valid if value is null', function () {\n    // given\n\n    // when\n    var valid = maxLengthValidator.validate(null, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/maxValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrMaxValidator', ['valdrUtil', function (valdrUtil) {\n\n    return {\n      name: 'max',\n\n      /**\n       * Checks if the value is a number and lower or equal as the value specified in the constraint.\n       *\n       * @param value the value to validate\n       * @param constraint the validation constraint\n       * @returns {boolean} true if valid\n       */\n      validate: function (value, constraint) {\n        var maxValue = Number(constraint.value),\n          valueAsNumber = Number(value);\n\n        if (valdrUtil.isNaN(value)) {\n          return false;\n        }\n\n        return valdrUtil.isEmpty(value) || valueAsNumber <= maxValue;\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/maxValidator.spec.js",
    "content": "describe('valdrMaxValidator', function () {\n\n  var maxValidator, constraint;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrMaxValidator) {\n    maxValidator = valdrMaxValidator;\n    constraint = { value: '10' };\n  }));\n\n  it('should provide the correct name', function () {\n    expect(maxValidator.name).toBe('max');\n  });\n\n  it('should return true for empty values', function () {\n    expect(maxValidator.validate('', constraint)).toBe(true);\n    expect(maxValidator.validate(null, constraint)).toBe(true);\n    expect(maxValidator.validate(undefined, constraint)).toBe(true);\n  });\n\n  it('should return false for NaN', function () {\n    expect(maxValidator.validate(NaN, constraint)).toBe(false);\n  });\n\n  it('should return true for valid numbers', function () {\n    expect(maxValidator.validate('10', constraint)).toBe(true);\n    expect(maxValidator.validate(10, constraint)).toBe(true);\n    expect(maxValidator.validate('9', constraint)).toBe(true);\n    expect(maxValidator.validate(9, constraint)).toBe(true);\n    expect(maxValidator.validate('-9', constraint)).toBe(true);\n    expect(maxValidator.validate(-9, constraint)).toBe(true);\n    expect(maxValidator.validate('9.9999999', constraint)).toBe(true);\n  });\n\n  it('should return false for invalid numbers and strings', function () {\n    expect(maxValidator.validate(10.001, constraint)).toBe(false);\n    expect(maxValidator.validate('10.000001', constraint)).toBe(false);\n    expect(maxValidator.validate('11', constraint)).toBe(false);\n    expect(maxValidator.validate(11, constraint)).toBe(false);\n    expect(maxValidator.validate('string', constraint)).toBe(false);\n    expect(maxValidator.validate('number', constraint)).toBe(false);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/minLengthValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrMinLengthValidator', ['valdrUtil', function (valdrUtil) {\n    return {\n      name: 'minLength',\n\n      /**\n       * Checks if the value is a string and if it's at least 'constraint.number' of characters long.\n       *\n       * @param value the value to validate\n       * @param constraint with property 'number'\n       * @returns {boolean} true if valid\n       */\n      validate: function (value, constraint) {\n        var minLength = constraint.number;\n\n        if (valdrUtil.isEmpty(value)) {\n          return true;\n        }\n\n        if (typeof value === 'string') {\n          return value.length >= minLength;\n        } else {\n          return false;\n        }\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/minLengthValidator.spec.js",
    "content": "describe('valdrMinLengthValidator', function () {\n\n  var minLengthValidator, constraint = {\n    number: 5,\n    message: 'message'\n  };\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrMinLengthValidator) {\n    minLengthValidator = valdrMinLengthValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(minLengthValidator.name).toBe('minLength');\n  });\n\n  it('should return true if value is valid', function () {\n    // given\n    var value = 'valid-value';\n\n    // when\n    var valid = minLengthValidator.validate(value, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should return the validation result', function () {\n    // given\n    var value = 'a';\n\n    // when\n    var valid = minLengthValidator.validate(value, constraint);\n\n    // then\n    expect(valid).toBe(false);\n  });\n\n  it('should be valid if minLength is 0 and value undefined', function () {\n    // given\n    constraint.number = 0;\n\n    // when\n    var valid = minLengthValidator.validate(undefined, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should be invalid if value is number', function () {\n    // given\n    constraint.number = 4;\n\n    // when\n    var valid = minLengthValidator.validate(123, constraint);\n\n    // then\n    expect(valid).toBe(false);\n  });\n\n  it('should be valid if minLength is 0 and value null', function () {\n    // given\n    constraint.number = 0;\n\n    // when\n    var valid = minLengthValidator.validate(null, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should be valid if minLength is 1 and value undefined', function () {\n    // given\n    constraint.number = 1;\n\n    // when\n    var valid = minLengthValidator.validate(undefined, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should be valid if minLength is 1 and value null', function () {\n    // given\n    constraint.number = 1;\n\n    // when\n    var valid = minLengthValidator.validate(null, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/minValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrMinValidator', ['valdrUtil', function (valdrUtil) {\n\n    return {\n      name: 'min',\n\n      /**\n       * Checks if the value is a number and higher or equal as the value specified in the constraint.\n       *\n       * @param value the value to validate\n       * @param constraint the validation constraint\n       * @returns {boolean} true if valid\n       */\n      validate: function (value, constraint) {\n        var minValue = Number(constraint.value),\n          valueAsNumber = Number(value);\n\n\n        if (valdrUtil.isNaN(value)) {\n          return false;\n        }\n\n        return valdrUtil.isEmpty(value) || valueAsNumber >= minValue;\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/minValidator.spec.js",
    "content": "describe('valdrMinValidator', function () {\n\n  var minValidator, constraint;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrMinValidator) {\n    minValidator = valdrMinValidator;\n    constraint = { value: '10' };\n  }));\n\n  it('should provide the correct name', function () {\n    expect(minValidator.name).toBe('min');\n  });\n\n  it('should return true for empty values', function () {\n    expect(minValidator.validate('', constraint)).toBe(true);\n    expect(minValidator.validate(null, constraint)).toBe(true);\n    expect(minValidator.validate(undefined, constraint)).toBe(true);\n  });\n\n  it('should return false for NaN', function () {\n    expect(minValidator.validate(NaN, constraint)).toBe(false);\n  });\n\n  it('should return true for valid numbers', function () {\n    expect(minValidator.validate('10', constraint)).toBe(true);\n    expect(minValidator.validate(10, constraint)).toBe(true);\n    expect(minValidator.validate(10.001, constraint)).toBe(true);\n    expect(minValidator.validate('10.000001', constraint)).toBe(true);\n    expect(minValidator.validate('11', constraint)).toBe(true);\n    expect(minValidator.validate(11, constraint)).toBe(true);\n  });\n\n  it('should return false for invalid numbers and strings', function () {\n    expect(minValidator.validate('9', constraint)).toBe(false);\n    expect(minValidator.validate(9, constraint)).toBe(false);\n    expect(minValidator.validate('-9', constraint)).toBe(false);\n    expect(minValidator.validate(-9, constraint)).toBe(false);\n    expect(minValidator.validate('9.9999999', constraint)).toBe(false);\n    expect(minValidator.validate('string', constraint)).toBe(false);\n    expect(minValidator.validate('number', constraint)).toBe(false);\n    expect(minValidator.validate(' ', constraint)).toBe(false);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/pastValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrPastValidator', ['futureAndPastSharedValidator', function (futureAndPastSharedValidator) {\n\n    return {\n      name: 'past',\n\n      /**\n       * Checks if the value is a date in the past.\n       *\n       * @param value the value to validate\n       * @returns {boolean} true if empty, null, undefined or a date in the past, false otherwise\n       */\n      validate: function (value) {\n        return futureAndPastSharedValidator.validate(value, function (valueAsMoment, now) {\n          return valueAsMoment.isBefore(now);\n        });\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/pastValidator.spec.js",
    "content": "describe('valdrPastValidator', function () {\n\n  var pastValidator;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrPastValidator) {\n    pastValidator = valdrPastValidator;\n  }));\n\n  it('should be named \"past\"', function () {\n    expect(pastValidator.name).toBe('past');\n  });\n\n  it('should return true for empty values', function () {\n    expect(pastValidator.validate('')).toBe(true);\n    expect(pastValidator.validate(null)).toBe(true);\n    expect(pastValidator.validate(undefined)).toBe(true);\n  });\n\n  it('should return false for NaN', function () {\n    expect(pastValidator.validate(NaN)).toBe(false);\n  });\n\n  it('should return false for non-dates', function () {\n    expect(pastValidator.validate(' ')).toBe(false);\n    expect(pastValidator.validate('foo')).toBe(false);\n    expect(pastValidator.validate('_1.1.2014')).toBe(false);\n    expect(pastValidator.validate('31.2.2014')).toBe(false);\n    expect(pastValidator.validate('31:1:2014')).toBe(false);\n  });\n\n  it('should return false for dates in the future', function () {\n    expect(pastValidator.validate('1.1.2900')).toBe(false);\n    expect(pastValidator.validate('2030/12/31')).toBe(false);\n    expect(pastValidator.validate('2030-12-31')).toBe(false);\n    expect(pastValidator.validate(moment().add(10, 'seconds'))).toBe(false);\n  });\n\n  it('should return true for dates in the past', function () {\n    expect(pastValidator.validate('1.1.1900')).toBe(true);\n    expect(pastValidator.validate('01.01.1900')).toBe(true);\n    expect(pastValidator.validate('1. 1. 1900')).toBe(true);\n    expect(pastValidator.validate('01. 01. 1900')).toBe(true);\n    expect(pastValidator.validate('1-1-1900')).toBe(true);\n    expect(pastValidator.validate('01-01-1900')).toBe(true);\n    expect(pastValidator.validate('1/1/1900')).toBe(true);\n    expect(pastValidator.validate('01/01/1900')).toBe(true);\n    expect(pastValidator.validate('1900.1.1')).toBe(true);\n    expect(pastValidator.validate('1900.01.01')).toBe(true);\n    expect(pastValidator.validate('2000/12/31')).toBe(true);\n    expect(pastValidator.validate('2000-12-31')).toBe(true);\n    expect(pastValidator.validate(moment().subtract(10, 'seconds'))).toBe(true);\n  });\n});\n"
  },
  {
    "path": "src/core/validators/patternValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrPatternValidator', ['valdrUtil', function (valdrUtil) {\n\n    var REGEXP_PATTERN = /^\\/(.*)\\/([gim]*)$/;\n\n    /**\n     * Converts the given pattern to a RegExp.\n     * The pattern can either be a RegExp object or a string containing a regular expression (`/regexp/`).\n     * This implementation is based on the AngularJS ngPattern validator.\n     * @param pattern the pattern\n     * @returns {RegExp} the RegExp\n     */\n    var asRegExp = function (pattern) {\n      var match;\n\n      if (pattern.test) {\n        return pattern;\n      } else {\n        match = pattern.match(REGEXP_PATTERN);\n        if (match) {\n          return new RegExp(match[1], match[2]);\n        } else {\n          throw ('Expected ' + pattern + ' to be a RegExp');\n        }\n      }\n    };\n\n    return {\n      name: 'pattern',\n\n      /**\n       * Checks if the value matches the pattern defined in the constraint.\n       *\n       * @param value the value to validate\n       * @param constraint the constraint with the regexp as value\n       * @returns {boolean} true if valid\n       */\n      validate: function (value, constraint) {\n        var pattern = asRegExp(constraint.value);\n        return valdrUtil.isEmpty(value) || pattern.test(value);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/patternValidator.spec.js",
    "content": "describe('valdrPatternValidator', function () {\n\n  var patternValidator,\n    constraint = { value: '/^[a-z]+$/' };\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrPatternValidator) {\n    patternValidator = valdrPatternValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(patternValidator.name).toBe('pattern');\n  });\n\n  it('should return true for empty values', function () {\n    expect(patternValidator.validate('', constraint)).toBe(true);\n    expect(patternValidator.validate(undefined, constraint)).toBe(true);\n  });\n\n  it('should return true for matching values', function () {\n    expect(patternValidator.validate('asd', constraint)).toBe(true);\n  });\n\n  it('should return false for not matching values', function () {\n    expect(patternValidator.validate('123', constraint)).toBe(false);\n  });\n\n  it('should work with RegExp object in constraint', function () {\n    constraint.value = /^[a-z]+$/;\n    expect(patternValidator.validate('asd', constraint)).toBe(true);\n    expect(patternValidator.validate('123', constraint)).toBe(false);\n  });\n\n  it('should throw when RegExp is invalid', function () {\n    constraint.value = 'no RegExp';\n    expect(function () {\n      patternValidator.validate('asd', constraint);\n    }).toThrow();\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/requiredValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrRequiredValidator', ['valdrUtil', function (valdrUtil) {\n    return {\n      name: 'required',\n\n      /**\n       * Checks if the value is not empty.\n       *\n       * @param value the value to validate\n       * @returns {boolean} true if the value is not empty\n       */\n      validate: function (value) {\n        return valdrUtil.notEmpty(value);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/requiredValidator.spec.js",
    "content": "describe('valdrRequiredValidator', function () {\n\n  var requiredValidator, valdrUtil;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrRequiredValidator, _valdrUtil_) {\n    requiredValidator = valdrRequiredValidator;\n    valdrUtil = _valdrUtil_;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(requiredValidator.name).toBe('required');\n  });\n\n  it('should validate using the valdrUtil', function () {\n    // given\n    spyOn(valdrUtil, 'notEmpty');\n    var value = 'someValue';\n\n    // when\n    requiredValidator.validate(value);\n\n    // then\n    expect(valdrUtil.notEmpty).toHaveBeenCalledWith(value);\n  });\n\n  it('should return the validation result', function () {\n    expect(requiredValidator.validate('value')).toBe(true);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/sizeValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrSizeValidator', ['valdrUtil', function (valdrUtil) {\n    return {\n      name: 'size',\n\n      /**\n       * Checks if the values length is in the range specified by the constraints min and max properties.\n       *\n       * @param value the value to validate\n       * @param constraint with optional values: min, max\n       * @returns {boolean} true if valid\n       */\n      validate: function (value, constraint) {\n        var minLength = constraint.min || 0,\n          maxLength = constraint.max;\n\n        value = value || '';\n\n        if (valdrUtil.isEmpty(value)) {\n          return true;\n        }\n\n        return value.length >= minLength &&\n          (maxLength === undefined || value.length <= maxLength);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/sizeValidator.spec.js",
    "content": "describe('valdrSizeValidator', function () {\n\n  var sizeValidator, constraint = {\n    min: 5,\n    max: 20,\n    message: 'message'\n  };\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrSizeValidator) {\n    sizeValidator = valdrSizeValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(sizeValidator.name).toBe('size');\n  });\n\n  it('should return true if value is valid', function () {\n    // given\n    var value = 'valid-value';\n\n    // when\n    var valid = sizeValidator.validate(value, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should return the validation result', function () {\n    // given\n    var value = 'a';\n\n    // when\n    var valid = sizeValidator.validate(value, constraint);\n\n    // then\n    expect(valid).toBe(false);\n  });\n\n  it('should be valid if min is 0 and value undefined', function () {\n    // given\n    constraint.min = 0;\n\n    // when\n    var valid = sizeValidator.validate(undefined, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n  it('should be valid if min is 1 and value undefined', function () {\n    // given\n    constraint.min = 1;\n\n    // when\n    var valid = sizeValidator.validate(undefined, constraint);\n\n    // then\n    expect(valid).toBe(true);\n  });\n\n});\n"
  },
  {
    "path": "src/core/validators/urlValidator.js",
    "content": "angular.module('valdr')\n\n  .factory('valdrUrlValidator', ['valdrUtil', function (valdrUtil) {\n\n    // the url pattern used in angular.js\n    var URL_REGEXP = /^(ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?$/;\n\n    return {\n      name: 'url',\n\n      /**\n       * Checks if the value is a valid url.\n       *\n       * @param value the value to validate\n       * @returns {boolean} true if valid\n       */\n      validate: function (value) {\n        return valdrUtil.isEmpty(value) || URL_REGEXP.test(value);\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/core/validators/urlValidator.spec.js",
    "content": "describe('valdrUrlValidator', function () {\n\n  var urlValidator;\n\n  beforeEach(module('valdr'));\n\n  beforeEach(inject(function (valdrUrlValidator) {\n    urlValidator = valdrUrlValidator;\n  }));\n\n  it('should provide the correct name', function () {\n    expect(urlValidator.name).toBe('url');\n  });\n\n  it('should return true for empty values', function () {\n    expect(urlValidator.validate('')).toBe(true);\n    expect(urlValidator.validate(undefined)).toBe(true);\n  });\n\n  it('should return true for valid url', function () {\n    // some trivial tests\n    expect(urlValidator.validate('http://www.google.ch')).toBe(true);\n    expect(urlValidator.validate('http://server:123/path')).toBe(true);\n    // some tests from http://djpowell.net/atomrdf/0.1/files/uritest.xml\n    expect(urlValidator.validate('http://a/b/c/d;p?q#s')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/g?y#s')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/g..')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/d;p?y')).toBe(true);\n    expect(urlValidator.validate('http://a/b/c/g;x=1/y')).toBe(true);\n  });\n\n  it('should return false for invalid url', function () {\n    expect(urlValidator.validate('a@B.c')).toBe(false);\n    expect(urlValidator.validate('hanueli')).toBe(false);\n  });\n\n});\n"
  },
  {
    "path": "src/message/valdrMessage-directive.js",
    "content": "/**\n * This directive appends a validation message to the parent element of any input, select or textarea element, which\n * is nested in a valdr-type directive and has an ng-model bound to it.\n * If the form element is wrapped in an element marked with the class defined in valdrClasses.formGroup,\n * the messages is appended to this element instead of the direct parent.\n * To prevent adding messages to specific input fields, the attribute 'valdr-no-message' can be added to those input\n * or select fields. The valdr-message directive is used to do the actual rendering of the violation messages.\n */\nvar valdrMessageDirectiveDefinitionFactory = function (restrict) {\n    return ['$compile', function ($compile) {\n      return {\n        restrict: restrict,\n        require: ['?^valdrType', '?^ngModel', '?^valdrFormGroup'],\n        link: function (scope, element, attrs, controllers) {\n\n          var valdrTypeController = controllers[0],\n            ngModelController = controllers[1],\n            valdrFormGroupController = controllers[2],\n            valdrNoValidate = attrs.valdrNoValidate,\n            valdrNoMessage = attrs.valdrNoMessage,\n            fieldName = attrs.name;\n\n          /**\n           * Don't do anything if\n           * - this is an <input> that's not inside of a valdr-type or valdr-form-group block\n           * - there is no ng-model bound to input\n           * - there is a 'valdr-no-validate' or 'valdr-no-message' attribute present\n           */\n          if (!valdrTypeController || !valdrFormGroupController || !ngModelController ||\n            angular.isDefined(valdrNoValidate) || angular.isDefined(valdrNoMessage)) {\n            return;\n          }\n\n          var valdrMessageElement = angular.element('<span valdr-message=\"' + fieldName + '\"></span>');\n          $compile(valdrMessageElement)(scope);\n          valdrFormGroupController.addMessageElement(ngModelController, valdrMessageElement);\n\n          scope.$on('$destroy', function () {\n            valdrFormGroupController.removeMessageElement(ngModelController);\n          });\n\n        }\n      };\n    }];\n  },\n  valdrMessageElementDirectiveDefinition = valdrMessageDirectiveDefinitionFactory('E'),\n  valdrMessageAttributeDirectiveDefinition = valdrMessageDirectiveDefinitionFactory('A');\n\n\nvar nullValdrType = {\n  getType: angular.noop\n};\n\nangular.module('valdr')\n  .directive('input', valdrMessageElementDirectiveDefinition)\n  .directive('select', valdrMessageElementDirectiveDefinition)\n  .directive('textarea', valdrMessageElementDirectiveDefinition)\n  .directive('enableValdrMessage', valdrMessageAttributeDirectiveDefinition)\n\n/**\n * The valdr-message directive is responsible for the rendering of violation messages. The template used for rendering\n * is defined in the valdrMessage service where it can be overridden or a template URL can be configured.\n */\n  .directive('valdrMessage',\n  ['$rootScope', '$injector', 'valdrMessage', 'valdrUtil', function ($rootScope, $injector, valdrMessage, valdrUtil) {\n    return {\n      replace: true,\n      restrict: 'A',\n      scope: {\n        formFieldName: '@valdrMessage'\n      },\n      templateUrl: function () {\n        return valdrMessage.templateUrl;\n      },\n      require: ['^form', '?^valdrType'],\n      link: function (scope, element, attrs, controllers) {\n        var formController = controllers[0],\n          valdrTypeController = controllers[1] || nullValdrType;\n\n        var updateTranslations = function () {\n          if (valdrMessage.translateAvailable && angular.isArray(scope.violations)) {\n            angular.forEach(scope.violations, function (violation) {\n              valdrMessage.$translate(valdrMessage.fieldNameKeyGenerator(violation))\n                .then(function (translation) {\n                  violation.fieldName = translation;\n                })\n                .catch(angular.noop);\n            });\n          }\n        };\n\n        var createViolation = function (validatorName) {\n          var typeName = valdrTypeController.getType(),\n            fieldName = scope.formFieldName;\n\n          return {\n            type: typeName,\n            field: fieldName,\n            validator: validatorName,\n            message: valdrMessage.getMessage(typeName, fieldName, validatorName)\n          };\n        };\n\n        var addViolationsToScope = function () {\n          scope.violations = [];\n\n          angular.forEach(scope.formField.valdrViolations, function (violation) {\n            scope.violations.push(violation);\n          });\n\n          if (valdrMessage.angularMessagesEnabled) {\n            angular.forEach(scope.formField.$error, function (isValid, validatorName) {\n              if (!valdrUtil.startsWith(validatorName, 'valdr')) {\n                scope.violations.push(createViolation(validatorName));\n              }\n            });\n          }\n\n          scope.violation = scope.violations[0];\n          updateTranslations();\n        };\n        var removeViolationsFromScope = function () {\n          scope.violations = undefined;\n          scope.violation = undefined;\n        };\n\n        var watchFormFieldErrors = function () {\n          scope.formField = formController[scope.formFieldName];\n          if (scope.formField) {\n            return {\n              valdr: scope.formField.valdrViolations,\n              error: scope.formField.$error\n            };\n          }\n        };\n\n\n        scope.$watch(watchFormFieldErrors, function () {\n          if (scope.formField && scope.formField.$invalid) {\n            addViolationsToScope();\n          } else {\n            removeViolationsFromScope();\n          }\n        }, true);\n\n        var unregisterTranslateChangeHandler = $rootScope.$on('$translateChangeSuccess', function () {\n          updateTranslations();\n        });\n\n        scope.$on('$destroy', function () {\n          unregisterTranslateChangeHandler();\n        });\n      }\n    };\n  }]);\n"
  },
  {
    "path": "src/message/valdrMessage-directive.spec.js",
    "content": "describe('valdrMessage input directive', function () {\n\n  var $scope, $compile;\n\n  beforeEach(module('valdr'));\n\n  var compileTemplate = function (template) {\n    var element = $compile(angular.element(template))($scope);\n    $scope.$digest();\n    return element;\n  };\n\n  beforeEach(inject(function ($rootScope, _$compile_) {\n    $compile = _$compile_;\n    $scope = $rootScope.$new();\n    $scope.myObject = { field: 'fieldValue' };\n  }));\n\n\n  it('should add a the valdr-message directive after the input field and bind it to the correct form field',\n    function () {\n      // given\n      var element = compileTemplate(\n        '<form name=\"demoForm\">' +\n          '<div valdr-type=\"TestClass\" valdr-form-group>' +\n            '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\">' +\n          '</div>' +\n        '</form>'\n      );\n\n      // when\n      var nextElement = element.find('input').next()[0];\n\n      //then\n      expect(nextElement.attributes['valdr-message']).toBeDefined();\n      expect(nextElement.attributes['valdr-message'].value).toBe('fieldName');\n    });\n\n\n  it('should add a the valdr-message directive to the form group if there is one', function () {\n    // given\n    var element = compileTemplate(\n            '<form name=\"demoForm\">' +\n              '<section valdr-form-group>' +\n                '<div valdr-type=\"TestClass\">' +\n                  '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\">' +\n                '</div>' +\n              '</section>' +\n            '</form>'\n    );\n\n    // when\n    var formGroupChildren = element.find('section').children();\n    var lastInFormGroup = formGroupChildren[formGroupChildren.length - 1];\n\n    //then\n    expect(lastInFormGroup.attributes['valdr-message']).toBeDefined();\n    expect(lastInFormGroup.attributes['valdr-message'].value).toBe('fieldName');\n  });\n\n  it('should NOT add a the valdr-message after the input if valdr-no-message is set', function () {\n    // given\n    var element = compileTemplate(\n      '<form name=\"demoForm\">' +\n        '<div valdr-form-group valdr-type=\"TestClass\">' +\n        '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\" valdr-no-message>' +\n        '</div>' +\n      '</form>'\n    );\n\n    // when\n    var nextElement = element.find('input').next();\n\n    //then\n    expect(nextElement.length).toBe(0);\n  });\n\n  it('should NOT add a the valdr-message after the input is not wrapped in a valdr-type', function () {\n    // given\n    var element = compileTemplate(\n      '<form name=\"demoForm\">' +\n        '<div>' +\n        '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\">' +\n        '</div>' +\n      '</form>'\n    );\n\n    // when\n    var nextElement = element.find('input').next();\n\n    //then\n    expect(nextElement.length).toBe(0);\n  });\n\n  it('should NOT add valdr-message after the input if valdr-no-validate is set', function () {\n    // given\n    var element = compileTemplate(\n        '<form name=\"demoForm\">' +\n          '<div valdr-type=\"TestClass\" valdr-form-group>' +\n            '<input type=\"text\" name=\"fieldName\" ng-model=\"myObject.field\" valdr-no-validate>' +\n          '</div>' +\n        '</form>'\n    );\n    // when\n    var nextElement = element.find('input').next();\n\n    //then\n    expect(nextElement.length).toBe(0);\n  });\n\n});\n\ndescribe('valdrMessage directive', function () {\n\n  var $scope, $compile, valdrMessage;\n\n  beforeEach(module('valdr'));\n\n  var compileTemplate = function (template) {\n    var html = template ||\n      '<form name=\"testForm\">' +\n        '<input type=\"text\" name=\"testField\" ng-model=\"model\">' +\n        '<span valdr-message=\"testField\"></span>' +\n      '</form>';\n    var element = $compile(angular.element(html))($scope);\n    $scope.$digest();\n    return element;\n  };\n\n  var addViolations = function () {\n    // manually add some violations for the tests (these are usually added if the field is invalid)\n    $scope.testForm.testField.valdrViolations = [\n      { message: 'message-1' },\n      { message: 'message-2' }\n    ];\n    $scope.testForm.testField.$error = { valdr: [] };\n    $scope.testForm.testField.$invalid = true;\n    $scope.$digest();\n  };\n\n  var compileTemplateAndAddViolations = function (template) {\n    var element = compileTemplate(template);\n    addViolations();\n    return element;\n  };\n\n  beforeEach(inject(function ($rootScope, _$compile_, _valdrMessage_) {\n    $compile = _$compile_;\n    $scope = $rootScope.$new();\n    valdrMessage = _valdrMessage_;\n  }));\n\n  it('should display the first message in the default template', function () {\n    // when\n    var element = compileTemplateAndAddViolations();\n\n    // then\n    expect(element.find('div').html()).toBe('message-1');\n  });\n\n  it('should update the messages in the default template', function () {\n    // given\n    var element = compileTemplateAndAddViolations();\n\n    // when\n    $scope.testForm.testField.valdrViolations[0].message = 'updatedMessage';\n    $scope.$digest();\n\n    // then\n    expect(element.find('div').html()).toBe('updatedMessage');\n  });\n\n  it('should support custom templates', function () {\n    // given\n    valdrMessage.setTemplate('<div>Number of violations: {{ violations.length }}</div>');\n\n    // when\n    var element = compileTemplateAndAddViolations();\n\n    // then\n    expect(element.find('div').html()).toBe('Number of violations: 2');\n  });\n\n\n  it('should support dynamically added form items', function () {\n    // given\n    $scope.isVisible = false;\n    var element = compileTemplate(\n      '<form name=\"testForm\">' +\n        '<input type=\"text\" ng-if=\"isVisible\" name=\"testField\" ng-model=\"model\">' +\n        '<span valdr-message=\"testField\"></span>' +\n      '</form>');\n\n    // when\n    $scope.isVisible = true;\n    $scope.$digest();\n    addViolations();\n\n    // then\n    expect(element.find('div').html()).toBe('message-1');\n  });\n\n\n  it('should show messages for angular validators', function () {\n    // given\n    valdrMessage.angularMessagesEnabled = true;\n    valdrMessage.addMessages({\n      'required': 'This field is required'\n    });\n    var template =\n      '<form name=\"testForm\">' +\n        '<input required type=\"text\" name=\"testField\" ng-model=\"model\">' +\n        '<span valdr-message=\"testField\"></span>' +\n      '</form>';\n\n    // when\n    var element = $compile(angular.element(template))($scope);\n    $scope.$digest();\n\n    // then\n    expect(element.find('div').html()).toBe('This field is required');\n  });\n\n  it('should not show messages for angular validators by default', function () {\n    // given\n    valdrMessage.addMessages({\n      'required': 'This field is required'\n    });\n    var template =\n      '<form name=\"testForm\">' +\n        '<input required type=\"text\" name=\"testField\" ng-model=\"model\">' +\n        '<span valdr-message=\"testField\"></span>' +\n      '</form>';\n\n    // when\n    var element = $compile(angular.element(template))($scope);\n    $scope.$digest();\n\n    // then\n    expect(element.find('div').html()).toBe('');\n  });\n\n});\n\ndescribe('valdrMessage directive with angular-translate', function () {\n\n  var $scope, $compile, $translate, valdrMessage;\n\n  beforeEach(function () {\n    module('valdr');\n    module('pascalprecht.translate');\n    module(function ($translateProvider) {\n      $translateProvider.translations('en', {\n        'message-1': '{{fieldName}} english.',\n        'message-2': 'field: {{fieldName}} param: {{param}} secondParam: {{secondParam}}',\n        'Person.testField': 'Field Name'\n      });\n\n      $translateProvider.translations('de', {\n        'message-1': '{{fieldName}} deutsch.',\n        'message-2': 'field: {{fieldName}} param: {{param}} secondParam: {{secondParam}}',\n        'Person.testField': 'Feldname'\n      });\n\n      $translateProvider.preferredLanguage('en');\n    });\n  });\n\n  var compileTemplate = function () {\n    var html =\n      '<form name=\"testForm\">' +\n        '<input type=\"text\" name=\"testField\" ng-model=\"model\">' +\n        '<span valdr-message=\"testField\"></span>' +\n      '</form>';\n    var element = $compile(angular.element(html))($scope);\n\n    $scope.testForm.testField.valdrViolations = [\n      { message: 'message-1', field: 'testField', type: 'Person', param: '2' },\n      { message: 'message-2', field: 'testField', type: 'Person', param: '3' }\n    ];\n    $scope.testForm.testField.$error = { valdr: [] };\n    $scope.testForm.testField.$invalid = true;\n    $scope.$digest();\n    return element;\n  };\n\n  beforeEach(inject(function ($rootScope, _$compile_, _valdrMessage_, _$translate_) {\n    $compile = _$compile_;\n    $scope = $rootScope.$new();\n    $translate = _$translate_;\n    valdrMessage = _valdrMessage_;\n  }));\n\n  it('should translate the field name', function () {\n    // given\n    valdrMessage.setTemplate('<div>{{ violations[0].fieldName }}</div>');\n\n    // when\n    var element = compileTemplate();\n\n    // then\n    expect(element.find('div').html()).toBe('Field Name');\n  });\n\n  it('should translate the field name to german', function () {\n    // given\n    $translate.use('de');\n    valdrMessage.setTemplate('<div>{{ violations[0].fieldName }}</div>');\n\n    // when\n    var element = compileTemplate();\n\n    // then\n    expect(element.find('div').html()).toBe('Feldname');\n  });\n\n  it('should update field names on language switch at runtime', function () {\n    // given\n    valdrMessage.setTemplate('<div>{{ violations[0].fieldName }}</div>');\n    var element = compileTemplate();\n    expect(element.find('div').html()).toBe('Field Name');\n\n    // when\n    $translate.use('de');\n    $scope.$digest();\n\n    // then\n    expect(element.find('div').html()).toBe('Feldname');\n  });\n\n\n  it('should allow to use parameters in the translated messages', function () {\n    // given / when\n    var element = compileTemplate();\n    $scope.testForm.testField.valdrViolations = [\n      // note: message-2 has parameters defined in the translation tables\n      { message: 'message-2', field: 'testField', type: 'Person', param: '3', secondParam: '4' }\n    ];\n    $scope.$digest();\n\n    // then\n    expect(element.find('span').html()).toBe('field: Field Name param: 3 secondParam: 4');\n  });\n\n  it('should unregister translate change handler on destroy to avoid potential memory leaks', function () {\n    // given\n    var element = compileTemplate();\n    spyOn(valdrMessage, '$translate').andReturn({ then: function () {} });\n    $scope.$destroy();\n    element.remove();\n\n    // when\n    $translate.use('de');\n    $scope.$digest();\n\n    // then\n    expect(valdrMessage.$translate).not.toHaveBeenCalled();\n  });\n\n});\n\ndescribe('valdrMessage directive with angular-translate and valdrFieldNameKeyGenerator', function () {\n\n  var $scope, $compile, $translate, valdrMessage;\n\n  var fieldNameKeyGenerator = function(violation) {\n    return violation.type + '.' + violation.field + '.' + violation.validator + 'Name';\n  };\n\n  beforeEach(function () {\n    module('valdr');\n    module('pascalprecht.translate');\n    module(function ($translateProvider, $provide) {\n      $provide.factory('valdrFieldNameKeyGenerator', function() { return fieldNameKeyGenerator; });\n\n      $translateProvider.translations('en', {\n        'message-1': '{{fieldName}} english.',\n        'message-2': 'field: {{fieldName}} param: {{param}} secondParam: {{secondParam}}',\n        'Person.testField': 'Field Name',\n        'Person.testField.requiredName': 'The Field Name'\n      });\n\n      $translateProvider.translations('de', {\n        'message-1': '{{fieldName}} deutsch.',\n        'message-2': 'field: {{fieldName}} param: {{param}} secondParam: {{secondParam}}',\n        'Person.testField': 'Feldname',\n        'Person.testField.requiredName': 'Der Feldname'\n      });\n\n      $translateProvider.preferredLanguage('en');\n    });\n  });\n\n  var compileTemplate = function () {\n    var html =\n      '<form name=\"testForm\">' +\n      '<input type=\"text\" name=\"testField\" ng-model=\"model\">' +\n      '<span valdr-message=\"testField\"></span>' +\n      '</form>';\n    var element = $compile(angular.element(html))($scope);\n\n    $scope.testForm.testField.valdrViolations = [\n      { message: 'message-1', field: 'testField', type: 'Person', param: '2', validator: 'required' },\n      { message: 'message-2', field: 'testField', type: 'Person', param: '3', validator: 'required' }\n    ];\n    $scope.testForm.testField.$error = { valdr: [] };\n    $scope.testForm.testField.$invalid = true;\n    $scope.$digest();\n    return element;\n  };\n\n  beforeEach(inject(function ($rootScope, _$compile_, _valdrMessage_, _$translate_) {\n    $compile = _$compile_;\n    $scope = $rootScope.$new();\n    $translate = _$translate_;\n    valdrMessage = _valdrMessage_;\n  }));\n\n  it('should translate the field name using the fieldNameKeyGenerator', function () {\n    // given\n    valdrMessage.setTemplate('<div>{{ violations[0].fieldName }}</div>');\n\n    // when\n    var element = compileTemplate();\n\n    // then\n    expect(element.find('div').html()).toBe('The Field Name');\n  });\n\n  it('should translate the field name to german using the fieldNameKeyGenerator', function () {\n    // given\n    $translate.use('de');\n    valdrMessage.setTemplate('<div>{{ violations[0].fieldName }}</div>');\n\n    // when\n    var element = compileTemplate();\n\n    // then\n    expect(element.find('div').html()).toBe('Der Feldname');\n  });\n\n  it('should update field names on language switch at runtime', function () {\n    // given\n    valdrMessage.setTemplate('<div>{{ violations[0].fieldName }}</div>');\n    var element = compileTemplate();\n    expect(element.find('div').html()).toBe('The Field Name');\n\n    // when\n    $translate.use('de');\n    $scope.$digest();\n\n    // then\n    expect(element.find('div').html()).toBe('Der Feldname');\n  });\n\n\n  it('should allow to use parameters in the translated messages', function () {\n    // given / when\n    var element = compileTemplate();\n    $scope.testForm.testField.valdrViolations = [\n      // note: message-2 has parameters defined in the translation tables\n      { message: 'message-2', field: 'testField', type: 'Person', param: '3', secondParam: '4', validator: 'required' }\n    ];\n    $scope.$digest();\n\n    // then\n    expect(element.find('span').html()).toBe('field: The Field Name param: 3 secondParam: 4');\n  });\n\n});\n"
  },
  {
    "path": "src/message/valdrMessage-service.js",
    "content": "angular.module('valdr')\n\n/**\n * This service provides shared configuration between all valdr-message directive instances like the configured\n * template to render the violation messages and whether or not angular-translate is available.\n */\n  .provider('valdrMessage', function () {\n\n    var userDefinedTemplateUrl, userDefinedTemplate,\n      messages = {},\n      defaultTemplateUrl = 'valdr/default-message.html',\n      defaultTemplate =   '<div class=\"valdr-message\">' +\n                            '{{ violation.message }}' +\n                          '</div>',\n      translateTemplate = '<div class=\"valdr-message\" ng-show=\"violation\">' +\n                            '<span ' +\n                            'translate=\"{{ violation.message }}\" ' +\n                            'translate-values=\"violation\"></span>' +\n                          '</div>';\n\n    this.setTemplate = function (template) {\n      userDefinedTemplate = template;\n    };\n\n    this.setTemplateUrl = function (templateUrl) {\n      userDefinedTemplateUrl = templateUrl;\n    };\n\n    this.addMessages = function (newMessages) {\n      angular.extend(messages, newMessages);\n    };\n    var addMessages = this.addMessages;\n\n    this.getMessage = function (typeName, fieldName, validatorName) {\n      var fullMessageKey = typeName + '.' + fieldName + '.' + validatorName;\n      return messages[fullMessageKey] || messages[validatorName] || '[' + validatorName + ']';\n    };\n    var getMessage = this.getMessage;\n\n    this.$get = ['$templateCache', '$injector', function ($templateCache, $injector) {\n\n      var angularMessagesEnabled = false;\n\n      function getTranslateService() {\n        try {\n          return $injector.get('$translate');\n        } catch (error) {\n          return undefined;\n        }\n      }\n\n      function getFieldNameKeyGenerator() {\n        try {\n          return $injector.get('valdrFieldNameKeyGenerator');\n        } catch (error) {\n          return function(violation) {\n            return violation.type + '.' + violation.field;\n          };\n        }\n      }\n\n      var $translate = getTranslateService(),\n        translateAvailable = angular.isDefined($translate),\n        fieldNameKeyGenerator = getFieldNameKeyGenerator();\n\n      function determineTemplate() {\n        if (angular.isDefined(userDefinedTemplate)) {\n          return userDefinedTemplate;\n        } else if (translateAvailable) {\n          return translateTemplate;\n        } else {\n          return defaultTemplate;\n        }\n      }\n\n      function updateTemplateCache() {\n        $templateCache.put(defaultTemplateUrl, determineTemplate());\n        if (userDefinedTemplateUrl && userDefinedTemplate) {\n          $templateCache.put(userDefinedTemplateUrl, userDefinedTemplate);\n        }\n      }\n\n      updateTemplateCache();\n\n      return {\n        templateUrl: userDefinedTemplateUrl || defaultTemplateUrl,\n        setTemplate: function (newTemplate) {\n          userDefinedTemplate = newTemplate;\n          updateTemplateCache();\n        },\n        translateAvailable: translateAvailable,\n        $translate: $translate,\n        fieldNameKeyGenerator: fieldNameKeyGenerator,\n        addMessages: addMessages,\n        getMessage: getMessage,\n        angularMessagesEnabled: angularMessagesEnabled\n      };\n    }];\n  });\n"
  },
  {
    "path": "src/message/valdrMessage-service.spec.js",
    "content": "describe('valdrMessage service', function () {\n\n  var valdrMessage;\n\n  beforeEach(module('valdr'));\n  beforeEach(inject(function (_valdrMessage_) {\n    valdrMessage = _valdrMessage_;\n  }));\n\n  it('should provide the default templateUrl', function () {\n    expect(valdrMessage.templateUrl).toBe('valdr/default-message.html');\n  });\n\n  it('should detect that $translate is not available', function () {\n    expect(valdrMessage.translateAvailable).toBe(false);\n  });\n\n  it('should provide undefined for $translate', function () {\n    expect(valdrMessage.$translate).toBeUndefined();\n  });\n\n  it('should populate the $templateCache with the default template', function () {\n    inject(function ($templateCache) {\n      // given\n      var templateUrl = valdrMessage.templateUrl;\n\n      // when\n      var template = $templateCache.get(templateUrl);\n\n      // then\n      expect(template).toBeDefined();\n      expect(template).toBe('<div class=\"valdr-message\">{{ violation.message }}</div>');\n    });\n  });\n\n});\n\ndescribe('valdrMessage service with angular-translate', function () {\n\n  var valdrMessage;\n\n  beforeEach(module('valdr'));\n  beforeEach(module('pascalprecht.translate'));\n  beforeEach(inject(function (_valdrMessage_) {\n    valdrMessage = _valdrMessage_;\n  }));\n\n  it('should provide the default templateUrl', function () {\n    expect(valdrMessage.templateUrl).toBe('valdr/default-message.html');\n  });\n\n  it('should detect that $translate is available', function () {\n    expect(valdrMessage.translateAvailable).toBe(true);\n  });\n\n  it('should provide $translate service', function () {\n    expect(valdrMessage.$translate).toBeDefined();\n    expect(typeof valdrMessage.$translate).toBe('function');\n  });\n\n  it('should populate the $templateCache with the angular-translate template', function () {\n    inject(function ($templateCache) {\n      // given\n      var templateUrl = valdrMessage.templateUrl;\n\n      // when\n      var template = $templateCache.get(templateUrl);\n\n      // then\n      expect(template).toBeDefined();\n      expect(template).toBe('<div class=\"valdr-message\" ng-show=\"violation\">' +\n                              '<span ' +\n                              'translate=\"{{ violation.message }}\" ' +\n                              'translate-values=\"violation\"></span>' +\n                            '</div>');\n    });\n  });\n\n});\n\ndescribe('valdrMessageProvider', function () {\n\n  it('should provide the custom template URL and NOT populate $templateCache', function () {\n    // given\n    var customTemplateUrl = 'custom/template.html';\n    module('valdr');\n\n    // when\n    module(function (valdrMessageProvider) {\n      valdrMessageProvider.setTemplateUrl(customTemplateUrl);\n    });\n\n    // then\n    inject(function (valdrMessage, $templateCache) {\n      expect(valdrMessage.templateUrl).toBe(customTemplateUrl);\n      expect($templateCache.get(valdrMessage.templateUrl)).toBeUndefined();\n    });\n  });\n\n  it('should populate $templateCache with the custom template', function () {\n    // given\n    var customTemplate = '<div>my template</div>';\n    module('valdr');\n\n    // when\n    module(function (valdrMessageProvider) {\n      valdrMessageProvider.setTemplate(customTemplate);\n    });\n\n    // then\n    inject(function (valdrMessage, $templateCache) {\n      var template = $templateCache.get(valdrMessage.templateUrl);\n      expect(template).toBe(customTemplate);\n    });\n  });\n\n\n  it('should populate $templateCache with the custom template and custom URL', function () {\n    // given\n    var customTemplate = '<div>my template</div>';\n    var customTemplateUrl = 'custom/my-template.html';\n    module('valdr');\n\n    // when\n    module(function (valdrMessageProvider) {\n      valdrMessageProvider.setTemplateUrl(customTemplateUrl);\n      valdrMessageProvider.setTemplate(customTemplate);\n    });\n\n    // then\n    inject(function (valdrMessage, $templateCache) {\n      expect(valdrMessage.templateUrl).toBe(customTemplateUrl);\n      var template = $templateCache.get(valdrMessage.templateUrl);\n      expect(template).toBe(customTemplate);\n    });\n  });\n\n  it('should allow to add and get messages', function () {\n    // given\n    module('valdr');\n\n    // when\n    module(function (valdrMessageProvider) {\n      valdrMessageProvider.addMessages({\n        'validator': 'validator-global-error-message',\n        'Type.field.validator': 'fully-qualified-error-message'\n      });\n    });\n\n    // then\n    inject(function (valdrMessage) {\n      expect(valdrMessage.getMessage('Type', 'field', 'validator')).toEqual('fully-qualified-error-message');\n      expect(valdrMessage.getMessage(undefined, undefined, 'validator')).toEqual('validator-global-error-message');\n      expect(valdrMessage.getMessage(undefined, undefined, 'unknown')).toEqual('[unknown]');\n    });\n\n  });\n\n});\n"
  },
  {
    "path": "src/valdr.js",
    "content": "angular.module('valdr', ['ng'])\n  .constant('valdrEvents', {\n    'revalidate': 'valdr-revalidate'\n  })\n  .value('valdrConfig', {\n    addFormGroupClass: true\n  })\n  .value('valdrClasses', {\n    formGroup: 'form-group',\n    valid: 'ng-valid',\n    invalid: 'ng-invalid',\n    dirty: 'ng-dirty',\n    pristine: 'ng-pristine',\n    touched: 'ng-touched',\n    untouched: 'ng-untouched',\n    invalidDirtyTouchedGroup: 'valdr-invalid-dirty-touched-group'\n  });"
  },
  {
    "path": "src/valdr.spec.js",
    "content": "describe('valdr', function () {\n\n  beforeEach(module('valdr'));\n\n  it('should provide constant for validation events', inject(function (valdrEvents) {\n    expect(valdrEvents).toBeDefined();\n  }));\n\n  it('should provide constant for revalidate event', inject(function (valdrEvents) {\n    expect(valdrEvents.revalidate).toBe('valdr-revalidate');\n  }));\n\n  it('should provide a value for valdrClasses', inject(function (valdrClasses) {\n    expect(valdrClasses.valid).toBe('ng-valid');\n    expect(valdrClasses.invalid).toBe('ng-invalid');\n    expect(valdrClasses.invalidDirtyTouchedGroup).toBe('valdr-invalid-dirty-touched-group');\n  }));\n\n});"
  }
]