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

feat(form): interpolate form names #5231

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ var nullFormCtrl = {
*
*/
//asks for $scope to fool the BC controller module
FormController.$inject = ['$element', '$attrs', '$scope'];
function FormController(element, attrs) {
FormController.$inject = ['$element', '$attrs', '$scope', '$interpolate'];
function FormController(element, attrs, $scope, $interpolate) {
var form = this,
parentForm = element.parent().controller('form') || nullFormCtrl,
invalidCount = 0, // used to easily determine if we are valid
errors = form.$error = {},
controls = [];

// init state
form.$name = attrs.name || attrs.ngForm;
form.$name = $interpolate(attrs.name || attrs.ngForm || '', false)($scope);
form.$dirty = false;
form.$pristine = true;
form.$valid = true;
Expand Down
18 changes: 18 additions & 0 deletions test/ng/directive/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ describe('form', function() {
expect(scope.obj.myForm).toBeTruthy();
});

it('should support a template as form name', function() {
scope.data = [ 'first', 'second' ];
doc = $compile(
'<form name="myForm">' +
'<div ng-repeat="(key, value) in data" ng-form name="children_{{ key }}"></div>' +
// '<div ng-repeat="(key, value) in data" ng-form name="children[{{ key }}]"></div>' +
'</form>')(scope);

scope.$apply();

expect(scope.myForm).toBeDefined();
expect(scope.myForm.children_0).toBeDefined();
expect(scope.myForm.children_1).toBeDefined();
// expect(scope.myForm.children).toBeDefined();
// expect(scope.myForm.children[0]).toBeDefined();
// expect(scope.myForm.children[1]).toBeDefined();
})


it('should support two forms on a single scope', function() {
doc = $compile(
Expand Down