mardi 24 mars 2020

how to implement oncheck event of td on one2many list view

I have added a checkbox to my one2many field listview(using the web_one2many_selectable_10 module) I want to get every id of the selected line in my one2many field oncheck of the check box instead of onclick of the "Create DR" button

one2many checkbox

here's the javascript code

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

    var core = require('web.core');
    var form_common = require('web.form_common');
    var _t = core._t;
    var QWeb = core.qweb;
    var Model = require('web.Model');
    var FieldOne2Many = core.form_widget_registry.get('one2many');


    var One2ManySelectable = FieldOne2Many.extend({
        // my custom template for unique char field
        template: 'One2ManySelectable', 

        multi_selection: true,
        //button click
        events: {
            "click td.o_list_record_selector": "get_id_lines",
        },
        start: function() 
        {
            this._super.apply(this, arguments);
            var self=this;          
           },
        get_id_lines: function(e){
            var self=this;
            console.log('im here')

        },
        //collecting the selected IDS from one2manay list
        get_selected_ids_one2many: function ()
        {
            var ids =[];
            this.$el.find('td.o_list_record_selector input:checked')
                    .closest('tr').each(function () {

                        ids.push(parseInt($(this).context.dataset.id));
                        console.log(ids);
            });
            return ids;
        },


    });
    // register unique widget, because Odoo does not know anything about it
    //you can use <field name="One2many_ids" widget="x2many_selectable"> for call this widget
    core.form_widget_registry.add('one2many_selectable', One2ManySelectable);
});

When I change the code

events: {
            "click td.o_list_record_selector": "get_id_lines",
        },

to

events: {
            "click th.o_list_record_selector": "get_id_lines",
        },

it is working fine but when i also check the checkbox in the td of the table it wont call the get_id_lines function it's only working when i check the checkbox on the thead part of the table




Aucun commentaire:

Enregistrer un commentaire