Я хочу вызвать функцию js в Odoo из XML
<template id = "portal_my_attendances_inherit" name = "My Attendances"
inherit_id = "hr_attendance_portal.portal_my_attendances">
<xpath expr = "//t[@t-call='portal.portal_searchbar']" position = "after">
<div class = "mb4">
<t t-if = "env.user.employee_id">
<a t-if = "env.user.employee_id.attendance_state != 'checked_in'"
href = "#" class = "btn btn-success checkInBtn">Check Inn <i class = "fa fa-sign-in"/></a>
<t t-else = "">
<a href = "#" class = "btn btn-warning checkOutBtn">Check Out <i class = "fa fa-sign-out"/></a>
<strong> Hours today:</strong>
<span t-field = "env.user.employee_ids.hours_today" t-options = "{'widget': 'float_time'}"/>
<small>(refresh page to update)</small>
</t>
</t>
</div>
</xpath>
</template>
/** @odoo-module **/
import publicWidget from '@web/legacy/js/public/public_widget';
console.info('Start ...');
publicWidget.registry.portalAttendance = publicWidget.Widget.extend({
selector: '.checkInBtn, .checkOutBtn',
events: {
'click .checkInBtn': '_onCheckInClicked',
'click .checkOutBtn': '_onCheckOutClicked',
},
_onCheckInClicked: function (ev) {
ev.preventDefault();
console.info('In Button clicked !!!');
},
_onCheckOutClicked: function (ev) {
ev.preventDefault();
console.info('Out Button clicked !!!');
},
});
export default publicWidget.registry.portalAttendance;
В консоли печатается «Начать...», но когда я нажимаю кнопку «Проверить», я не получаю 'В кнопке нажата!!!' сообщение. Может кто-нибудь мне помочь, пожалуйста.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Селектор должен быть родительским для элементов события, поэтому вам следует его обновить.
В элемент <div class = "mb4">, заключающий в себе элемент события, теперь добавлен новый класс под названием wrap-div.
<template id = "portal_my_attendances_inherit" name = "My Attendances" inherit_id = "hr_attendance_portal.portal_my_attendances">
<xpath expr = "//t[@t-call='portal.portal_searchbar']" position = "after">
<div class = "mb4 wrap-div">
<t t-if = "env.user.employee_id">
<a t-if = "env.user.employee_id.attendance_state != 'checked_in'" href = "#" class = "btn btn-success checkInBtn">Check Inn <i class = "fa fa-sign-in"/></a>
<t t-else = "">
<a href = "#" class = "btn btn-warning checkOutBtn">Check Out <i class = "fa fa-sign-out"/></a>
<strong> Hours today:</strong>
<span t-field = "env.user.employee_ids.hours_today" t-options = "{'widget': 'float_time'}" />
<small>(refresh page to update)</small>
</t>
</t>
</div>
</xpath>
</template>
Затем,
selector: '.wrap-div',