Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make read-write field in OpenERP/Odoo ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 311
    Comment on it

    In Read-only fields, which only display content and don't allow the user to modify it can be useful, but most fields in Odoo also allow editing.
    In the write field the Abstract field class sets a widget property named effective_readonly. The field should watch for changes in that widget property and display the correct mode accordingly. For example code is like below.

    local.FieldChar2 = instance.web.form.AbstractField.extend({
        init: function() {
            this._super.apply(this, arguments);
            this.set("value", "");
        },
        start: function() {
            this.on("change:effective_readonly", this, function() {
                this.display_field();
                this.render_value();
            });
            this.display_field();
            return this._super();
        },
        display_field: function() {
            var self = this;
            this.$el.html(QWeb.render("FieldChar2", {widget: this}));
            if (! this.get("effective_readonly")) {
                this.$("input").change(function() {
                    self.internal_set_value(self.$("input").val());
                });
            }
        },
        render_value: function() {
            if (this.get("effective_readonly")) {
                this.$el.text(this.get("value"));
            } else {
                this.$("input").val(this.get("value"));
            }
        },
    });
    
    instance.web.form.widgets.add('char2', 'instance.oepetstore.FieldChar2');
    <t t-name="FieldChar2">
        <div class="oe_field_char2">
            <t t-if="! widget.get('effective_readonly')">
                <input type="text">
            </t>
        </div>
    </t>
    

    Note- This makes the field classes more complicated, mostly because fields are supposed to handle both editable and non-editable mode, those modes are often completely different and the fields must be able to switch between modes at any moment.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: