İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
2963 Görünümler

Hi,


I 'm building a custom view and I want to redirect to menu item when a user click on an div element. 


I tried something like that in my template

<a t-attf-href="#menu_id=MENU_ID">...</a>

 

And it works, but it breaks the browser history.


Maybe there is way to do this from the js but I can't something that match my need


Any clue ?


Regards











Avatar
Vazgeç
En İyi Yanıt

try this way:
template>

div id="myDivElement">Click here to go to the menu item

/template>


JS:
odoo.define('my_module.my_view', function (require) {

'use strict';


var core = require('web.core');


$(document).ready(function () {

// Get the menu ID you want to redirect to

var menuID = YOUR_MENU_ITEM_ID;


// Add a click event listener to the div element

$('#myDivElement').on('click', function () {

// Redirect to the specified menu item

core.bus.trigger('menu_item_clicked', menuID);

});

});


});


Replace YOUR_MENU_ITEM_ID with the actual ID of the menu item you want to redirect to. When the user clicks on the div element, the event listener will be triggered, and it will call the core.bus.trigger method with the 'menu_item_clicked' event, which will navigate to the specified menu item without breaking the browser history.

Avatar
Vazgeç
En İyi Yanıt

Hi,

You can try this code

<a t-attf-href="/web#id={{object.id}}&amp;cids={{object.env.user.id}}&amp;menu_id={{object.env.ref('module_name.menuitem_id').id}}&amp;action={{object.env.ref('module_name.action_id').id}}&amp;model=model.name&amp;view_type=form" style="background-color:#875a7b;padding:8px 16px 8px 16px;text-decoration:none;color:#fff;border-radius:5px;font-size:13px">Click Here</a>

this is the example for adding button click and the corresponding actions
  

Hope it helps

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Nis 16
10190
0
Kas 23
1510
0
Oca 23
1978
1
Ağu 22
2853
0
Haz 22
4287