Permalink
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.- Loading branch information
Showing
with
34 additions
and 6 deletions.
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html ng-app> | ||
| <body> | ||
| <form> | ||
| <input type="hidden" value="{{value}}" /> | ||
| <button ng-click="value = '{{ 7 * 6 }}'">Click me</button> | ||
| </form> | ||
| <script src="angular.js"></script> | ||
| </body> | ||
| </html> |
| @@ -0,0 +1,15 @@ | ||
| describe('hidden thingy', function() { | ||
| it('should pass', function() { | ||
|
|
||
| loadFixture('input-hidden'); | ||
| expect(element(by.css('input')).getAttribute('value')).toEqual(''); | ||
|
|
||
| element(by.css('button')).click(); | ||
| expect(element(by.css('input')).getAttribute('value')).toEqual('{{ 7 * 6 }}'); | ||
|
|
||
| loadFixture('sample'); | ||
| browser.driver.executeScript('history.back()'); | ||
| var expectedValue = browser.params.browser === 'safari' ? '{{ 7 * 6 }}' : ''; | ||
| expect(element(by.css('input')).getAttribute('value')).toEqual(expectedValue); | ||
| }); | ||
| }); |