Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
1107 Vizualizări

Hello,


I have added new button in Odoo form view and want to call  onclick event from JavaScript instead of adding method in python.

Is there any way to do this?

<button name="create_crm_records" class="mt-5 btn btn-info import_button_click">Import</button>

Thanks.


Regards,

Hemangi.

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Extend the "web.FormView" template and add a new button.

<templates xml:space="preserve">

   <t t-inherit="web.FormView" t-inherit-mode="extension">

       <xpath expr="//button[contains(@class, 'o_form_button_create')]" position="before">

           <button type="button" class="btn btn-primary history_btn" id="history_btn"

               t-on-click="buttonClicked">

               <span>NEW BUTTON</span>

           </button>

       </xpath>

   </t></templates>

Need to create a JS file inside static/src/js directory(eg :static/src/js/form_button.js)

import { patch } from "@web/core/utils/patch";

import { FormController } from "@web/views/form/form_controller";


patch(FormController.prototype, {

    setup() {

        super.setup();

    },

    buttonClicked() {

    // Add your code

    },

});


Hope it helps

Imagine profil
Abandonează
Autor

Hello Cybrosys Techno Solutions Pvt.Ltd,

Thanks for your reply. My button is not near the Create button.

Its inside Form view of crm.lead view. Do you know how to do for that type of button?

Thanks.

Regards,
Hemangi.

Related Posts Răspunsuri Vizualizări Activitate
1
mai 25
1125
1
apr. 25
1008
0
mar. 25
640
1
iun. 25
765
0
feb. 25
1075