Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Property Management
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Add a javascript function linked to a button in an xml view

Subscriure's

Get notified when there's activity on this post

This question has been flagged
3 Respostes
15737 Vistes
Avatar
JJB Conseil

Hi everyone,


i need to add a button in an xml view wich call a javascript function

No problem to add the button, but i'm not able to add the js function.


Is it possible to have a complete example code to add a js function in odoo, and how link this function to the onclick event of the button.


Thank you by advance

Vincent

0
Avatar
Descartar
Hilar Andikkadavath

please check form controller which is dealing create, edit buttons events.

addons/web/static/src/js/views/form/form_controller.js

Avatar
Daniel Lagin
Best Answer

Hi,

 1. in your custom module create static.xml and add it into manifest.

'data': [
...
'views/static.xml',
],

 2. views/static.xml:

<odoo>
<data>
<template id="my_module_assets" name="my_module.assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/my_module/static/src/js/button.js"></script>
</xpath>
</template>
</data>
</odoo>

In your custom module create: /my_module/static/src/js/button.js

3. in button declaration add class or id for created button:

<button name="button" class="my_class" string="Call"/>

4. in button.js (/my_module/static/src/js/button.js) create function to trigger js code after button click:

events: {
"click . my_class": "call_function",
},
call_function: function () {
    console.log('Click')
},
1
Avatar
Descartar
Avatar
JJB Conseil
Autor Best Answer

Hi Daniel,

Thank you for all those details.

I tried with your solution but i've got an error (see below) :

ERROR: TestUi.test_01_admin_bank_statement_reconciliation Traceback (most recent call last): File "/home/odoo/src/odoo/addons/account/tests/test_reconciliation_widget.py", line 38, in test_01_admin_bank_statement_reconciliation 'bank_statement_reconciliation', login="admin") File "/home/odoo/src/odoo/odoo/tests/common.py", line 1251, in start_tour res = self.browser_js(url_path=url_path, code=code, ready=ready, **kwargs) File "/home/odoo/src/odoo/odoo/tests/common.py", line 1223, in browser_js self.assertTrue(self.browser._wait_ready(ready), 'The ready "%s" code was always falsy' % ready) File "/home/odoo/src/odoo/odoo/tests/common.py", line 924, in _wait_ready res = self._get_message() File "/home/odoo/src/odoo/odoo/tests/common.py", line 801, in _get_message raise ChromeBrowserException(descr or pprint.pformat(exception_details)) odoo.tests.common.ChromeBrowserException: SyntaxError: Unexpected token ':'

Any idea for this error!?

Please find below my code : views/clipboard.xml, clipboard.js and button declaration

I've addedd clipboard.xml in manifest file

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <template
id="safar_module_asset" name="safar_module.assets" inherit_id="web.assets_backend">
            <xpath
expr="." position="inside">
                <script
type="text/javascript" src="/safar_module/static/src/js/clipboard.js"/>
            </xpath>
        </template>
    </data>
</odoo>

 
events: {
   
“click . class_js_safar”: “read_from_clipboard”,
},
read_from_clipboard:
function() {
    console.log(
'alert log')
},

 
<button name="Recup_safar_config"
string="Récupérer Config"
type="object"
class="class_js_safar"/>

Hope you can help me

Vincent

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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