Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
2952 Представления

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











Аватар
Отменить
Лучший ответ

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.

Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
апр. 16
10165
0
нояб. 23
1476
0
янв. 23
1955
1
авг. 22
2809
0
июн. 22
4268