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

Commit 663788d

Browse files
committed
docs(changelog, migration): add BC notice for allowed form name values
Introduced by 94533e5 Closes #13771
1 parent af0574e commit 663788d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

CHANGELOG.md

+37
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,43 @@ describe('$q.when', function() {
15191519
});
15201520
```
15211521

1522+
- **form:** Due to [94533e57](https://github.com/angular/angular.js/commit/94533e570673e6b2eb92073955541fa289aabe02),
1523+
the `name` attribute of `form` elements can now only contain characters that can be evaluated as part
1524+
of an Angular expression. This is because Angular uses the value of `name` as an assignable expression
1525+
to set the form on the `$scope`. For example, `name="myForm"` assigns the form to `$scope.myForm` and
1526+
`name="myObj.myForm"` assigns it to `$scope.myObj.myForm`.
1527+
1528+
Previously, it was possible to also use names such `name="my:name"`, because Angular used a special setter
1529+
function for the form name. Now the general, more robust `$parse` setter is used.
1530+
1531+
The easiest way to migrate your code is therefore to remove all special characters from the `name` attribute.
1532+
1533+
If you need to keep the special characters, you can use the following directive, which will replace
1534+
the `name` with a value that can be evaluated as an expression in the compile function, and then
1535+
re-set the original name in the postLink function. This ensures that (1), the form is published on
1536+
the scope, and (2), the form has the original name, which might be important if you are doing server-side
1537+
form submission.
1538+
1539+
```js
1540+
angular.module('myApp').directive('form', function() {
1541+
return {
1542+
restrict: 'E',
1543+
priority: 1000,
1544+
compile: function(element, attrs) {
1545+
var unsupportedCharacter = ':'; // change accordingly
1546+
var originalName = attrs.name;
1547+
if (attrs.name && attrs.name.indexOf(unsupportedCharacter) > 0) {
1548+
attrs.$set('name', 'this["' + originalName + '"]');
1549+
}
1550+
1551+
return postLinkFunction(scope, element) {
1552+
// Don't trigger $observers
1553+
element.setAttribute('name', originalName);
1554+
}
1555+
}
1556+
};
1557+
});
1558+
```
15221559

15231560
<a name="1.4.3"></a>
15241561
# 1.4.3 foam-acceleration (2015-07-15)

docs/content/guide/migration.ngdoc

+41
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,47 @@ ngModelCtrl.$formatters.push(function(value) {
473473
});
474474
```
475475

476+
477+
### form
478+
479+
Due to [94533e57](https://github.com/angular/angular.js/commit/94533e570673e6b2eb92073955541fa289aabe02),
480+
the `name` attribute of `form` elements can now only contain characters that can be evaluated as part
481+
of an Angular expression. This is because Angular uses the value of `name` as an assignable expression
482+
to set the form on the `$scope`. For example, `name="myForm"` assigns the form to `$scope.myForm` and
483+
`name="myObj.myForm"` assigns it to `$scope.myObj.myForm`.
484+
485+
Previously, it was possible to also use names such `name="my:name"`, because Angular used a special setter
486+
function for the form name. Now the general, more robust `$parse` setter is used.
487+
488+
The easiest way to migrate your code is therefore to remove all special characters from the `name` attribute.
489+
490+
If you need to keep the special characters, you can use the following directive, which will replace
491+
the `name` with a value that can be evaluated as an expression in the compile function, and then
492+
re-set the original name in the postLink function. This ensures that (1), the form is published on
493+
the scope, and (2), the form has the original name, which might be important if you are doing server-side
494+
form submission.
495+
496+
```js
497+
angular.module('myApp').directive('form', function() {
498+
return {
499+
restrict: 'E',
500+
priority: 1000,
501+
compile: function(element, attrs) {
502+
var unsupportedCharacter = ':'; // change accordingly
503+
var originalName = attrs.name;
504+
if (attrs.name && attrs.name.indexOf(unsupportedCharacter) > 0) {
505+
attrs.$set('name', 'this["' + originalName + '"]');
506+
}
507+
508+
return postLinkFunction(scope, element) {
509+
// Don't trigger $observers
510+
element.setAttribute('name', originalName);
511+
}
512+
}
513+
};
514+
});
515+
```
516+
476517
### Templating (`ngRepeat`, `$compile`)
477518

478519
#### ngRepeat

0 commit comments

Comments
 (0)