Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Autocomplete input on frontend

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
autocompletefrontend
1 Svar
5593 Visninger
Avatar
Francesco Ballerini

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>


0
Avatar
Kassér
Avatar
Francesco Ballerini
Forfatter Bedste svar

I managed to make it work for my specific use case, since I provided a little example on 'country_id' I will also provide the snippet with the solution. I've adapted some things to make it works on Odoo 14

I had some trouble to make the autocomplete() solution working with countries because it will fail with 'unexpected token' if you don't trim the " ' " from some countries, that's why I used replace() in this snippet.

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="portal_details_autocomplete_snippet" inherit_id="portal.portal_my_details" name="User Profile">
<xpath expr="//form" position="inside">
<script src="/web/static/lib/jquery/jquery.js" type="text/javascript"/>
<script type="text/javascript">
<!-- Send readonly field to backend if any -->
$('Form').on('submit', function() {
$('select').prop('disabled', false);
});
</script>
<script src="/web/static/lib/jquery.ui/jquery-ui.js" type="text/javascript"/>
<script type="text/javascript">
$(document).ready(function() {
var availableCountries =<t t-esc="[country_id.name.replace('\'', '') for country_id in countries]"/>;
console.log(availableCountries)
$('.country_autocomplete').autocomplete({
source: availableCountries
});
});
</script>
</xpath>
<xpath expr="//form//select[@name='country_id']//parent::div" position="after">
<div t-attf-class="form-group #{error.get('country_id') and 'o_has_error' or ''} col-xl-6">
<label class="col-form-label" for="country_id">Country ID (Test)</label>
<input type="text" name="country_id"
t-attf-class="form-control #{error.get('country_id') and 'is-invalid' or ''} country_autocomplete"
t-att-value="country_id or partner.country_id"/>
</div>
</xpath>
</template>
</odoo>


0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Front-end Odoo language
frontend
Avatar
Avatar
1
aug. 22
7926
Sensitive form field has not disabled autocomplete
autocomplete
Avatar
Avatar
4
nov. 20
6961
What is we-button, we-collapse like things?
frontend
Avatar
0
jul. 20
4167
URL
url frontend
Avatar
0
nov. 23
2309
custom layout in form views
layout frontend
Avatar
Avatar
1
jul. 23
4553
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now