Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6787 Lượt xem

I have created my own widget to be called in tree views this way:

<field name="selected" widget="toggle_switch"/>

The field selected is of type boolean. I created the widget class extending the Column class:

var ListView = require('web.ListView');
var ToggleSwitch = ListView.Column.extend({
   ...
})

And I have registered it this way:

var core = require('web.core');
core.list_widget_registry.add('field.toggle_switch', ToggleSwitch);

And it is working, but now I want to modify the value of the selected field each time the user clicks on the main element of the template I made for the widget.

The problem is that I am not able to do that. It seems that events dictionary is not available for the Column class, and I cannot use something like this.on('click', this, this.on_click); or this.$el.find(...), as this brings only the field data.

Can anyone help me? Should I inherit from other classes to use events in my widget (in fact I have tried, but in every case my Qweb template just disappeared from the tree view...)?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

You can do with the following js code.

odoo.define('listview_click', function(require) {
"use strict";

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

ListView.List.include({
init: function(group, opts) {
this._super.apply(this, arguments);
this.$current.delegate('td label.switch', 'click', function(e) {
e.stopPropagation();
// execute your code here, like:
var checked = $(e.currentTarget).find('input').prop('checked');
});
}
});
});

Regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 6 21
4
0
thg 6 21
5
1
thg 8 22
2614
5
thg 7 19
8293
2
thg 8 24
6628