Permalink
Comparing changes
Open a pull request
- 2 commits
- 3 files changed
- 0 commit comments
- 1 contributor
Commits on Oct 11, 2016
…history.back This reverts commit 693d133. There was a regression against angular-material that relied upon the input directive having `link.pre` property.
…ory.back
Due to the nature of some browser's PageCache/BFCache, returning to an Angular
app sometimes causes `input[hidden]` elements to retain the last value
that was stored before the page was navigated away from previously.
This is particularly problematic if the input has an interpolated value.
E.g. `<input type="hidden" value="{{ 1 + 2 }}">` since when the browser
returns, instead of the original interpolation template, the HTML contains
the previous value `<input type="hidden" value="3">`.
This commit instructs the browser not to attempt to reinstate the previous
value when navigating back in history by setting `autocomplete="off"` on
the hidden input element element.
Unified
Split
Showing
with
19 additions
and 10 deletions.
- +11 −1 src/ng/compile.js
- +6 −9 src/ng/directive/input.js
- +2 −0 test/e2e/tests/input-hidden.spec.js
| @@ -1538,13 +1538,17 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | ||
| var nodeType = node.nodeType, | ||
| attrsMap = attrs.$attr, | ||
| match, | ||
| nodeName, | ||
| className; | ||
|
|
||
| switch (nodeType) { | ||
| case NODE_TYPE_ELEMENT: /* Element */ | ||
|
|
||
| nodeName = nodeName_(node); | ||
|
|
||
| // use the node name: <directive> | ||
| addDirective(directives, | ||
| directiveNormalize(nodeName_(node)), 'E', maxPriority, ignoreDirective); | ||
| directiveNormalize(nodeName), 'E', maxPriority, ignoreDirective); | ||
|
|
||
| // iterate over the attributes | ||
| for (var attr, name, nName, ngAttrName, value, isNgAttr, nAttrs = node.attributes, | ||
| @@ -1585,6 +1589,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | ||
| attrEndName); | ||
| } | ||
|
|
||
| if (nodeName === 'input' && node.getAttribute('type') === 'hidden') { | ||
| // Hidden input elements can have strange behaviour when navigating back to the page | ||
| // This tells the browser not to try to cache and reinstate previous values | ||
| node.setAttribute('autocomplete', 'off'); | ||
| } | ||
|
|
||
| // use class as directive | ||
| className = node.className; | ||
| if (isObject(className)) { | ||
| @@ -1708,16 +1708,13 @@ var inputDirective = ['$browser', '$sniffer', '$filter', '$parse', | ||
| return { | ||
| restrict: 'E', | ||
| require: ['?ngModel'], | ||
| compile: function(tElement, tAttr) { | ||
| if (lowercase(tAttr.type) === 'hidden') tAttr.$set('autocomplete', 'off'); | ||
| return { | ||
| pre: function(scope, element, attr, ctrls) { | ||
| if (ctrls[0]) { | ||
| (inputType[lowercase(attr.type)] || inputType.text)(scope, element, attr, ctrls[0], $sniffer, | ||
| $browser, $filter, $parse); | ||
| } | ||
| link: { | ||
| pre: function(scope, element, attr, ctrls) { | ||
| if (ctrls[0]) { | ||
| (inputType[lowercase(attr.type)] || inputType.text)(scope, element, attr, ctrls[0], $sniffer, | ||
| $browser, $filter, $parse); | ||
| } | ||
| }; | ||
| } | ||
| } | ||
| }; | ||
| }]; | ||
| @@ -1,3 +1,5 @@ | ||
| 'use strict'; | ||
|
|
||
| describe('hidden thingy', function() { | ||
| it('should pass', function() { | ||
|
|
||