Make field invisible via js code - ODOO 9

642 views Asked by At

I'm looking for a method which makes a field invisible on js (i'm making a custom widget 'InvisibleIfEmptry'). I tried to override _check_visibility method when extending FormWidget.AbstractField class :

var core = require('web.core'),
        form_common = require('web.form_common');
var InvisibleIfEmpty = form_common.AbstractField.extend({
start: function() {
            this.on("change:effective_readonly", this, function() {
                this._toggle_label();
                this._check_visibility();
            });
            this.render_value();
            this._toggle_label();
        },
_check_visibility: function() {
            if (this.get("effective_readonly"))
                this.$el.toggleClass('o_form_invisible',true);   
            }
                this.$el.toggleClass('o_form_invisible',false);
            }
        }, .....

but this makes invisible only the field's value, not the label. my guess is to alter some of field_manager's values but i can't figure out which one ?

Thank you for your help :)

1

There are 1 answers

0
Nero Ouali On BEST ANSWER

Here is my JS code for doing that :

odoo.define('myCustomModule', function(require)
{
    'use strict';
    var core = require('web.core'),
        form_common = require('web.form_common'),
        form_view = require('web.FormView');

    form_common.AbstractField.include({

        start: function() {

            this._super();
            // Check visibility logic below when content
            // changes or the form swich to view mode
            this.field_manager.on("view_content_has_changed", this, function() {
                this._check_visibility();
            });
            this.on("change:effective_readonly", this, function() {
                this._toggle_label();
                this._check_visibility();
        });
        },

        _check_visibility: function() {

            // If the form is in view mode and the field is empty,
            // make the field invisible
            window.alert(this.);
            if (this.field_manager.get("actual_mode") === "view" ) {
                if(this.get("value") == false){
                    this.$el.toggleClass('o_form_invisible',true);
                    this.$label.toggleClass('o_form_invisible',true);
                }else{
                    this.$el.toggleClass('o_form_invisible',this.get("effective_invisible"));
                    this.$label.toggleClass('o_form_invisible',this.get("effective_invisible"));
                }
            }else{
                this.$el.toggleClass('o_form_invisible',this.get("effective_invisible"));
                this.$label.toggleClass('o_form_invisible',this.get("effective_invisible"));
            }
        },
    });

});

But this applies to all my modules. Does Any one know how to get module/model name from AbstractField ?