Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Restauration & Hôtellerie
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Bricoleur
    • Matériel informatique & support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Parcourir toutes les industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenir partenaire
    • Services pour partenaires
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

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

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
3 Réponses
15746 Vues
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
Ignorer
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
Meilleure réponse

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
Ignorer
Avatar
JJB Conseil
Auteur Meilleure réponse

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
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenir partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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