This question has been flagged

Hello,

I creating a Website module. I have a form created using  a template. All is working well. I dont have any javascript file for now. I would like to add a field, that call a python function when the value change. The python function will give back a result that I would like to display on the same form.

I saw many example that use a javascript Widget the get it work, but no example for frontend (website).

I try to add a simple Javascript file to test if my Javascript is loaded, but not working.

This is my code.

test_module/views/templates.xml

<template id="assets_frontend_test" inherit_id="website.assets_frontend" name="Assets Frontend test">
    <xpath expr="." position="inside">
        <script type="text/javascript" src='/test_module/static/src/js/test.js'></script>    
    </xpath>
</template>

<template id="test">
    <t t-call="website.layout">
     <t t-set="title">TEST</t>
        <div class="oe_structure">
         <div class="container">
             test
            </div>
     </div>
    </t>
</template>


test_module/static/src/js/test.js

(function () {
    'use strict';
    var _t = openerp._t;
    var website = openerp.website;
website.add_template_file('/test_module/views/template.xml');
   
    website.Test = openerp.Widget.extend({
        template: 'test_module.test',
        start: function() {
            console.log("TEST WIDGET!!!");
},
});

    website.ready().done(function() {
console.log("test READY!!!!");
var test = new website.Test();
});
})();

 

How can I do it work? I am not sure of what I do with template on JS file. On frontend, we use QWeb to display a template...

Can you help me to make this example work?  After, I know that I have to add "event" to call onchange function that call XMLRPC.

Thanks


Avatar
Discard

Did you find the answer?

Author Best Answer

I forgot to paste my controller:

controllers.py

@http.route('/page/test/', type='http', auth='user', website=True)
def test(self, **kw):
    return request.render('test_module.test', {})
Avatar
Discard