-
Notifications
You must be signed in to change notification settings - Fork 621
Select box selection is not restored when using back button (works in turbolinks-classic) #238
Comments
I just hit the same issue. The problem appears to be that the page is saved and restored by taking a snapshot of the DOM, which for a select box does not include information about any changes to selection since the page was loaded. The following code (coffeescript) adds an event handler which is fired just prior to the page being saved by Turbolinks. It finds all With the selection information now in the DOM, the selection is now restored after navigating away then back to the page containing the form.
|
Thanks @richardcrichardc! I had same issue, but I'm using selectize for my resetSelectized = (index, select) ->
selectedValue = select.selectize.getValue()
select.selectize.destroy()
if selectedValue
$select = $(select)
$select.find('option').attr('selected', null)
$select.find("option[value=#{selectedValue}]").attr('selected', true)
document.addEventListener 'turbolinks:before-cache', ->
$('.selectized').each resetSelectized |
$(document).ready(function() { }); |
The only viable solution I found for this issue was to disable caching by setting response headers:
At first I had a hard time debugging this issue because I had the developer-tools open with caching disabled 🤦 I'm not sure how it is actually supposed to behave?! Is it expected behavior that after a redirct-after-post and a broser-back-button the initial form-data is supposed to be presented to the user? That feels so weird! |
Hello, this approach has helped me fix a problem where a select would stop working when clicking back on the browser, however, now the select dropdown options are the browser native ones without the custom styling, I have tried to do |
Hi
This can easily be reproduced with a blank new rails app. I've created one here: https://github.com/pierre-pretorius/turbolinks_test
The text was updated successfully, but these errors were encountered: