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

How to make a custom widget editable only when i click 'Edit' button?

By
Sajad KK
on 5/20/14, 12:20 AM 1,372 views

I have created a custom rating widget in openerp using Rateit.

But the widget is always editable, How can i make it editable only when i click 'Edit' button and How do i know it is in readonly mode?

xml

<field name="rating" widget="rating"/>

js

instance.my_module.Rating = instance.web.form.FieldChar.extend({
        template : "rating",
        init: function(field_manager, node){
            this._super.apply(this, arguments);

        },

        start: function() {

            var self = this;

            $('#rateit').rateit({
                value: 0,
                resetable: false
            });
        },
    });

0
Sajad KK
On 5/20/14, 2:35 AM

Finally i got it working, here is my code

start: function() {

            var self = this;
            this.field_manager.has_been_loaded.done(function() {
                $('#rateit').rateit({
                    value: 0,
                    resetable: false
                });
                self.field_manager.on("change:actual_mode", self, self.check_actual_mode);
                self.check_actual_mode();
            });

 },
 
 check_actual_mode: function(source, options) {
    var self = this;
    if(self.field_manager.get("actual_mode")=='view'){
        $('#rateit').rateit('readonly',true);
    }
    else {
        $('#rateit').rateit('readonly',false);
    }
}

0
George
On 7/14/16, 8:34 AM

Hi Sajad,

I have created a widget but with out clicking edit button i am able to give input to it. I tried to use your code but it tells me rateit method not found. What to give inside rateit ?.

Please help me i am struck 

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

3 follower(s)

Stats

Asked: 5/20/14, 12:20 AM
Seen: 1372 times
Last updated: 7/14/16, 8:34 AM