Odoo Help

2

3
1 Answer
3
Ikss France
3/11/13, 11:37 AM

Solution :

In web_example.xml :

 <record model="ir.ui.view" id="test_form_view">
        <field name="name">test.form</field>
        <field name="model">test</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="test">
                <field name="numero"  widget="test"/>    
            </form>
        </field>
 </record>

Then in static/src/xml create a qweb file : test.xml

<templates>
 <div t-name="test_button" t-attf-class="base #{cls}" class="oe_web_example">  
   <p>
    <button name="dosomething" type="object" id="bstart">start</button>
   </p>
 </div>
</templates>

and finally static/src/js/function.js

    openerp.web_example = function(openerp) {
      openerp.web.form.widget.add('test','openerp.web.form.test');


    openerp.web.form.test = openerp.web.form.FieldChar.extend(
    {    
       template: 'test_button',

       init: function () {
                 this._super.apply(this, arguments);
                 this._start = null;
                 console.log('INIT');

       },

       start: function() {
             console.log('START');   
             $('button#bstart').click(this.myfunction);  //link button to function  
        },

        myfunction: function() {
              //DO WHAT YOU WANT
        }
...

You have created a widget based on a fieldchar which displays a button. This button is linked to a javascript function.

2 Comments
justeUnPseudo France
6/24/13, 7:03 AM

Good, but your example is not complete and don't work for me :/

sengottuvel India
9/20/13, 2:15 AM

Hi Team,

I want to do some validation using java script in OpenERP7.

Eg:

I have a form view and it contains qty and pending_qty fields. If user entered qty is greater than pending_qty i want to show a error using java script.

Is it possible and how can i achieve this ? Kindly help me..Thanks in advance

Ask a Question
Writer
Keep Informed
2 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now