I'm using Autocomplete jQuery UI in one my project and I want to destroy autocomplete in one case.
I have a web page where there are 2 fields i.e Country
and Ext No
. Where user choose a country I'm triggering an ajax call to get all ext no for that country. If there are any ext no available for that country then I have set the autocomplete list on Ext No
field. So where ext no is exist for a country then I'm able to set new autocomplete list on the Ext No
field. But there are some countries which don't have any ext no, so in that case I want to destroy autocomplete list on Ext No
field.
Below is the code I'm using to destroy autocomplete on Ext No
field.
if ($('#ext_no').data('autocomplete')) {
$('#ext_no').autocomplete("destroy");
}
But this is not working. I'm always getting $('#ext_no').data('autocomplete')
as undefined
. For the very first time it was undefined that's fine but when user choose a country for next time it should not return undefined
.
Let me know if anyone has any idea what I'm doing wrong here or is there any other way to destroy autocomplete for field if it was set on that field.