I have a select with thousands of elements to show on frontend page but it loads very slowly so I want to use autocomplete input.
I got a simple script here as example: https://jqueryui.com/autocomplete/ and it works on my frontend page but when I switch the example list with my list of elements it raise the following error:
TypeError: this.source is not a function
http://127.0.0.1:8069/web/static/lib/jquery.ui/jquery-ui.js:7602
Traceback:
_search@http://127.0.0.1:8069/web/static/lib/jquery.ui/jquery-ui.js:7602:8
$.widget/search@http://127.0.0.1:8069/web/static/lib/jquery.ui/jquery-ui.js:7594:15
$.widget/_searchTimeout/this.searchinghandlerProxy@http://127.0.0.1:8069/web/static/lib/jquery.ui/jquery-ui.js:641:6
I adapted my code to the res.country table data so it should be easy to test for anyone if you can help me with this. Log error doesn't say much to me because I don't know js framework, but when i t-out 'country_list' I can see list of strings. On _searchTimeout property I can read
// search timeout should be triggered before the input value is changed
So I guess it has something to do with promise resolve, async function.. all things I don't know very well : )
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="my_details_snippet" inherit_id="portal.portal_my_details" name="Details Snippet">
<xpath expr="//form" position="after">
<script src="/web/static/lib/jquery.ui/jquery-ui.js" type="text/javascript"/>
<script type="text/javascript">
$( function() {
var availableCountries = $( "select_country_list_by_class" );
$( "#tags" ).autocomplete({
source: availableCountries
});
} );
</script>
</xpath>
<xpath expr="//form//select[@name='country_id']//parent::div" position="after">
<t t-set="country_list" t-value="[str(country_id.name) for country_id in countries]" class="select_country_list_by_class" />
<t t-esc="country_list"/>
<div class="ui-widget">
<label for="tags">Tags:</label>
<input id="tags"/>
</div>
</xpath>
</template>
</odoo>