jquery autocomplete does not respond to dynamically inserted element

后端 未结 2 432
耶瑟儿~
耶瑟儿~ 2021-01-26 04:08

We are working on autocomplete with dynamically inserted elements with jquery (did autocomplete on static elements before). Here is the html source code for one autocomplete add

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-26 04:57

    setTimeout solves the problem:

     setTimeout(function(){
      $("[id^='requisition_material_items_attributes_'][id$='_item_name_autocomplete']").each(function (){
            $(this).autocomplete({
            minLength: 1,
            source: $(this).data('autocomplete-source'),
            select: function(event, ui) {
                $(this).val(ui.item.value);
            }
          });
        });
      }, 5000);
    

提交回复
热议问题