Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 8c606cc

Browse files
author
Caitlin Potter
committed
feat(input): interpolates form input name attrs for ngModel
1 parent 043190f commit 8c606cc

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/ng/directive/input.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ var VALID_CLASS = 'ng-valid',
953953
*
954954
*
955955
*/
956-
var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse',
957-
function($scope, $exceptionHandler, $attr, $element, $parse) {
956+
var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', '$interpolate',
957+
function($scope, $exceptionHandler, $attr, $element, $parse, $interpolate) {
958958
this.$viewValue = Number.NaN;
959959
this.$modelValue = Number.NaN;
960960
this.$parsers = [];
@@ -964,7 +964,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
964964
this.$dirty = false;
965965
this.$valid = true;
966966
this.$invalid = false;
967-
this.$name = $attr.name;
967+
this.$name = $interpolate($attr.name || '', false)($scope);
968968

969969
var ngModelGet = $parse($attr.ngModel),
970970
ngModelSet = ngModelGet.assign;

test/ng/directive/inputSpec.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,33 @@ describe('input', function() {
447447
});
448448

449449

450+
it('should interpolate input names (string)', function() {
451+
scope.nameID = '47';
452+
compileInput('<input type="text" ng-model="name" name="name{{nameID}}" />');
453+
expect(scope.form.name47.$pristine).toBeTruthy();
454+
changeInputValueTo('caitp');
455+
expect(scope.form.name47.$dirty).toBeTruthy();
456+
});
457+
458+
459+
it('should interpolate input names (number)', function() {
460+
scope.nameID = 47;
461+
compileInput('<input type="text" ng-model="name" name="name{{nameID}}" />');
462+
expect(scope.form.name47.$pristine).toBeTruthy();
463+
changeInputValueTo('caitp');
464+
expect(scope.form.name47.$dirty).toBeTruthy();
465+
});
466+
467+
468+
it('should interpolate input names (undefined)', function() {
469+
scope.nameID = undefined;
470+
compileInput('<input type="text" ng-model="name" name="name{{nameID}}" />');
471+
expect(scope.form.name.$pristine).toBeTruthy();
472+
changeInputValueTo('caitp');
473+
expect(scope.form.name.$dirty).toBeTruthy();
474+
});
475+
476+
450477
it('should not set readonly or disabled property on ie7', function() {
451478
this.addMatchers({
452479
toBeOff: function(attributeName) {

0 commit comments

Comments
 (0)