Skip to Content
Menu
This question has been flagged

\

I'm trying to re-render a template after something has changed on a QWeb webpage (onchange event on an element) with a set of new data. I'm used to working with JS frameworks like Vue and I have a problem with updating values on the QWeb webpage.

I don't see clear expalanation how to do this in the docs and while searching the internet and the source code I saw many different anwsers presumably for different Odoo versions. But both do not work.

I saw 2 main ways of doing this:

  • inside Python controller
  • inside JavaScript widget

And inside Python controller I saw different syntaxes and I'm not sure when to use what. For example:

# First method
@http.route('/test', type='json' auth='user', website=True)
def object(self, **kw):
    return http.request.render('template.name', {
        'value': kw.get('value', 0),
    })

# Second method
@http.route('/test', type='json' auth='user', website=True)
def object(self, **kw):
    return request.env['ir.ui.view'].render_template('template.name', {
        'value': kw.get('value', 0),
    })

Is there any difference between them? Also for some reason it does not render anything while calling it from JavaScript and using type='json'. It only renders when I use type='http' and go there directly from the browser - and I need a JS event to cause re-rendering.

I also saw that it is possible to render template from JavaScript like this:

_onChange: function () {
    console.log("something changed!");

    return this._rpc({
        route: '/test',
        params: {
            value: 1,
        }
    }).then(function (data) {
        this.$el.html(QWeb.render('template.name', {
            value: data.value
        }));
    });
},

But for some reason I get error Template 'template.name' not found.

I'm pretty stuck at this point and don't know what to do next. I can send data to and from controller. But I have no idea how to update variables on the QWeb. Please help.

Avatar
Discard

after extending the function add this in js.

xmlDependencies: ['/website_scanner/static/src/xml/inmate_listing.xml'],

This solved my issue

Related Posts Replies Views Activity
0
May 24
376
0
Jan 22
222
1
May 17
5803
1
May 16
5477
2
Jun 21
6067