jQuery UI autocomplete in remote modal RoR jQuery UI autocomplete in remote modal RoR database database

jQuery UI autocomplete in remote modal RoR


Since there is no working example, I just assume this its a timing issue like @muistooshort pointed out. You properly load your jquery part before the modal is updated. One option to overcome this, is by using Events. You want your code to be executed after your update your modal with the html-function.

Please try the following code:

$(document).on('modalUpdate', function(){  var data = $('#book_subcategory_name').data('autocomplete-source');  //... rest of your autocomplete code});//...start of your modal code$('.modal-backdrop').remove();$(modal_holder_selector).html(data).find(modal_selector).modal();$(document).trigger('modalUpdate'); //add this line//...rest of your modal code

depending on your application, you might want to change the event to something like contentUpdated, so it fits a more general purpose. You can name the Event what ever you like. You can read more on the jQuery article: Introducing Custom Events