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

Commit d3933a4

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

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

CHANGELOG.md

+37
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,43 @@ describe('$q.when', function() {
731731
});
732732
```
733733

734+
- **form:** Due to [94533e57](https://github.com/angular/angular.js/commit/94533e570673e6b2eb92073955541fa289aabe02),
735+
the `name` attribute of `form` elements can now only contain characters that can be evaluated as part
736+
of an Angular expression. This is because Angular uses the value of `name` as an assignable expression
737+
to set the form on the `$scope`. For example, `name="myForm"` assigns the form to `$scope.myForm` and
738+
`name="myObj.myForm"` assigns it to `$scope.myObj.myForm`.
739+
740+
Previously, it was possible to also use names such `name="my:name"`, because Angular used a special setter
741+
function for the form name. Now the general, more robust `$parse` setter is used.
742+
743+
The easiest way to migrate your code is therefore to remove all special characters from the `name` attribute.
744+
745+
If you need to keep the special characters, you can use the following directive, which will replace
746+
the `name` with a value that can be evaluated as an expression in the compile function, and then
747+
re-set the original name in the postLink function. This ensures that (1), the form is published on
748+
the scope, and (2), the form has the original name, which might be important if you are doing server-side
749+
form submission.
750+
751+
```js
752+
angular.module('myApp').directive('form', function() {
753+
return {
754+
restrict: 'E',
755+
priority: 1000,
756+
compile: function(element, attrs) {
757+
var unsupportedCharacter = ':'; // change accordingly
758+
var originalName = attrs.name;
759+
if (attrs.name && attrs.name.indexOf(unsupportedCharacter) > 0) {
760+
attrs.$set('name', 'this["' + originalName + '"]');
761+
}
762+
763+
return postLinkFunction(scope, element) {
764+
// Don't trigger $observers
765+
element.setAttribute('name', originalName);
766+
}
767+
}
768+
};
769+
});
770+
```
734771

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

docs/content/guide/migration.ngdoc

+40
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,46 @@ ngModelCtrl.$formatters.push(function(value) {
244244
});
245245
```
246246

247+
### form
248+
249+
Due to [94533e57](https://github.com/angular/angular.js/commit/94533e570673e6b2eb92073955541fa289aabe02),
250+
the `name` attribute of `form` elements can now only contain characters that can be evaluated as part
251+
of an Angular expression. This is because Angular uses the value of `name` as an assignable expression
252+
to set the form on the `$scope`. For example, `name="myForm"` assigns the form to `$scope.myForm` and
253+
`name="myObj.myForm"` assigns it to `$scope.myObj.myForm`.
254+
255+
Previously, it was possible to also use names such `name="my:name"`, because Angular used a special setter
256+
function for the form name. Now the general, more robust `$parse` setter is used.
257+
258+
The easiest way to migrate your code is therefore to remove all special characters from the `name` attribute.
259+
260+
If you need to keep the special characters, you can use the following directive, which will replace
261+
the `name` with a value that can be evaluated as an expression in the compile function, and then
262+
re-set the original name in the postLink function. This ensures that (1), the form is published on
263+
the scope, and (2), the form has the original name, which might be important if you are doing server-side
264+
form submission.
265+
266+
```js
267+
angular.module('myApp').directive('form', function() {
268+
return {
269+
restrict: 'E',
270+
priority: 1000,
271+
compile: function(element, attrs) {
272+
var unsupportedCharacter = ':'; // change accordingly
273+
var originalName = attrs.name;
274+
if (attrs.name && attrs.name.indexOf(unsupportedCharacter) > 0) {
275+
attrs.$set('name', 'this["' + originalName + '"]');
276+
}
277+
278+
return postLinkFunction(scope, element) {
279+
// Don't trigger $observers
280+
element.setAttribute('name', originalName);
281+
}
282+
}
283+
};
284+
});
285+
```
286+
247287
## Templating (`ngRepeat`, `$compile`)
248288

249289
### ngRepeat

0 commit comments

Comments
 (0)