user2320239 user2320239 - 2 months ago 11
Javascript Question

Tag input field not working with turbolinks

I'm trying to create a ruby on rails project, and as part of this project I'm using this jQuery plugin to manage tags input. However the tag field works on first refresh but not after any page loads, I'm pretty sure this is a problem with turbolinks not running the js again.

So I installed this gem, and changed:

$(function() {
$("input[data-role=tagsinput], select[multiple][data-role=tagsinput]").tagsinput();
});
})(window.jQuery);


to:

$(document).ready(function() {
$("input[data-role=tagsinput], select[multiple][data-role=tagsinput]").tagsinput();
});
})(window.jQuery);


in bootstrap-tagsinput.js.

However this is still giving me the same issues. Any help fixing this would be great.

Answer

try 'turoblinks:load'

instead

$(document).ready(function(){

use:

$(document).on('turbolinks:load',function(){
Comments