Skip to content

Commit

Permalink
Merge pull request #58 from zortnac/bugFix/dottedName
Browse files Browse the repository at this point in the history
Dotted strings in form name attribute
  • Loading branch information
Jakobovski committed Sep 25, 2015
2 parents adfc926 + 945fa85 commit d9032f1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/angular-validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
angular.module('angularValidator', []);

angular.module('angularValidator').directive('angularValidator', ['$injector',
function($injector) {
angular.module('angularValidator').directive('angularValidator', ['$injector', '$parse',
function($injector, $parse) {
return {
restrict: 'A',
link: function(scope, element, attrs, fn) {
Expand All @@ -15,7 +15,7 @@ angular.module('angularValidator').directive('angularValidator', ['$injector',
// This is the the scope form model
// All validation states are contained here
var form_name = DOMForm.attributes['name'].value;
var scopeForm = scope[form_name];
var scopeForm = $parse(form_name)(scope);

// Set the default submitted state to false
scopeForm.submitted = false;
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-validator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/angular-validator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
angular.module('angularValidator', []);

angular.module('angularValidator').directive('angularValidator', ['$injector',
function($injector) {
angular.module('angularValidator').directive('angularValidator', ['$injector', '$parse',
function($injector, $parse) {
return {
restrict: 'A',
link: function(scope, element, attrs, fn) {
Expand All @@ -15,7 +15,7 @@ angular.module('angularValidator').directive('angularValidator', ['$injector',
// This is the the scope form model
// All validation states are contained here
var form_name = DOMForm.attributes['name'].value;
var scopeForm = scope[form_name];
var scopeForm = $parse(form_name)(scope);

// Set the default submitted state to false
scopeForm.submitted = false;
Expand Down
29 changes: 29 additions & 0 deletions test/angular-validator-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@

var scope, compile;

describe('angularValidator with dotted name', function () {
var htmlForm, element, linkIt;

beforeEach(inject(function ($rootScope, $compile) {
scope = $rootScope.$new();
scope.object = {};

htmlForm = angular.element(
'<form name="object.form" angular-validator>' +
'<input ng-model="model.firstName" validate-on="dirty" name="firstName" type="text" required/>' +
'</form>'
);

linkIt = function () {
element = $compile(htmlForm)(scope);
scope.$digest();
};
}));

it('should not throw an error during linking', function () {
expect(linkIt).not.toThrow();
});

it('should correctly parse the dotted form name, evidenced by what\'s on scope', function () {
linkIt();
expect(scope.object.form).toBeDefined();
});
});

describe('angularValidator without form invalid message', function () {
beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new();
Expand Down

0 comments on commit d9032f1

Please sign in to comment.