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

Commit 7ec663f

Browse files
fix(input): ensure that hidden input values are correct after history.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.
1 parent 2687c26 commit 7ec663f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: src/ng/directive/input.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -899,11 +899,16 @@ var inputDirective = ['$browser', '$sniffer', function($browser, $sniffer) {
899899
return {
900900
restrict: 'E',
901901
require: '?ngModel',
902-
link: function(scope, element, attr, ctrl) {
903-
if (ctrl) {
904-
(inputType[lowercase(attr.type)] || inputType.text)(scope, element, attr, ctrl, $sniffer,
905-
$browser);
906-
}
902+
compile: function(tElement, tAttr) {
903+
if (lowercase(tAttr.type) === 'hidden') tAttr.$set('autocomplete', 'off');
904+
return {
905+
pre: function(scope, element, attr, ctrl) {
906+
if (ctrl) {
907+
(inputType[lowercase(attr.type)] || inputType.text)(scope, element, attr, ctrl, $sniffer,
908+
$browser);
909+
}
910+
}
911+
};
907912
}
908913
};
909914
}];

0 commit comments

Comments
 (0)