Error: cannot call methods on autocomplete prior to initialization; attempted to call method 'destroy' Error: cannot call methods on autocomplete prior to initialization; attempted to call method 'destroy' ajax ajax

Error: cannot call methods on autocomplete prior to initialization; attempted to call method 'destroy'


I got the answer to it in the initialization of autocomplete widget...just add

$(this.target).find('input').autocomplete();

This will initialize the autocomplete widget this happened because in 1.10.* .Jquery has added error messages for usage of functions without proper initialization whereas it was not there in previous versions.


If you want to make sure the autocomplete widget is destroyed, you can check if it was actually initialized by inspecting the CSS classes of the target element, e.g.

if ($target.hasClass('ui-autocomplete')) {    $target.autocomplete('destroy')}


I was getting similar error regarding the widget call,

console error

Inside the autocomplete initialization, we were calling its widget function, that was creating the console error.

In test-result.component.ts,

(<any> window).$(testelementId).autocomplete({……..(<any> window).$(this).autocomplete('widget').css('width', '100%');…..})

So, the easiest fix was to remove that particular call or place it after the initialization and test if that breaks any style. For me, removing the widget call is not doing any harm, so went ahead with that.