Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2961 Widoki

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











Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
kwi 16
10182
0
lis 23
1505
0
sty 23
1973
1
sie 22
2844
0
cze 22
4275