winmarkltd / BootstrapFormHelpers

Bootstrap Form Helpers
https://bootstrapformhelpers.com
1.16k stars 374 forks source link

Not compatible with rails 4 turbolinks #222

Closed sysout closed 10 years ago

sysout commented 10 years ago

For example, I have to refresh the page to make country & phone select works. Temporary solution: Disable turbolinks in rails 4.

lee-houghton commented 10 years ago

You've probably run into a similar problem as what we found with the time picker. The problem is that the code which turns the <div class="bfh-timepicker"> into the real thing only runs when the page loads. If you add it in later via AJAX or something like that, it won't get transformed. We solved it by adding the following after adding the elements into the DOM (where element is the part of the DOM we added into):

            if ($.fn.bfhtimepicker) {
                element.find('div.bfh-timepicker').each(function() {
                    var $timepicker = $(this);
                    $timepicker.bfhtimepicker($timepicker.data());
                });
            }

You'd have to modify this to work with the country and phone inputs of course (you can look at the BFH source to see what exactly you need to write)

I don't know anything about turbolinks, but it might offer some event that you can listen for, or hook that you can register for, so that you can run this code when turbolinks prefetches pages (I presume this is what turbolinks does?)

lee-houghton commented 10 years ago

Actually, there is apparently a jquery-turbolinks gem which should fix this for you.

https://github.com/kossnocorp/jquery.turbolinks

sysout commented 10 years ago

Thank you very much!