Skip to content

Commit d9032f1

Browse files
committed
Merge pull request Jakobovski#58 from zortnac/bugFix/dottedName
Dotted strings in form name attribute
2 parents adfc926 + 945fa85 commit d9032f1

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

dist/angular-validator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
angular.module('angularValidator', []);
22

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

2020
// Set the default submitted state to false
2121
scopeForm.submitted = false;

dist/angular-validator.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-validator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
angular.module('angularValidator', []);
22

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

2020
// Set the default submitted state to false
2121
scopeForm.submitted = false;

test/angular-validator-spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,35 @@
44

55
var scope, compile;
66

7+
describe('angularValidator with dotted name', function () {
8+
var htmlForm, element, linkIt;
9+
10+
beforeEach(inject(function ($rootScope, $compile) {
11+
scope = $rootScope.$new();
12+
scope.object = {};
13+
14+
htmlForm = angular.element(
15+
'<form name="object.form" angular-validator>' +
16+
'<input ng-model="model.firstName" validate-on="dirty" name="firstName" type="text" required/>' +
17+
'</form>'
18+
);
19+
20+
linkIt = function () {
21+
element = $compile(htmlForm)(scope);
22+
scope.$digest();
23+
};
24+
}));
25+
26+
it('should not throw an error during linking', function () {
27+
expect(linkIt).not.toThrow();
28+
});
29+
30+
it('should correctly parse the dotted form name, evidenced by what\'s on scope', function () {
31+
linkIt();
32+
expect(scope.object.form).toBeDefined();
33+
});
34+
});
35+
736
describe('angularValidator without form invalid message', function () {
837
beforeEach(inject(function($rootScope, $compile) {
938
scope = $rootScope.$new();

0 commit comments

Comments
 (0)