Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Website - Add onchange function that call Python function

By
Evans Bernier
on 6/12/16, 12:43 PM 619 views

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


0
Evans Bernier
On 6/13/16, 9:30 AM

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', {})

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/12/16, 12:43 PM
Seen: 619 times
Last updated: 6/13/16, 9:30 AM