Hello,
I'm trying to make a custom widget that makes fields invisible on "effective_readonly" if they're empty, and visible on "edit_mode".
Here is my try :
mymodule.js file
odoo.define('mymodule', function(require){
var core = require('web.core'),
form_common = require('web.form_common');
var InvisibleIfEmpty = form_common.AbstractField.extend({
init: function(field_manager, node)
{
this._super(field_manager, node);
this.set({'value' : ""});
},
renderElement: function () {
if (this.get("effective_readonly")) {
if(this.get("value") != ""){
this.set({ 'effective_invisible' : true});
}
else{
this.set({ 'effective_invisible' : false});
}
}else {
this.set({ 'effective_invisible' : false});
}
this._super();
},
});
core.form_widget_registry.add(
'invisibleIfEmpty', InvisibleIfEmpty);
return { InvisibleIfEmpty: InvisibleIfEmpty,}
});
And mymodule.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script src="/mymodule/static/src/js/mymodule.js" type="text/javascript" />
</xpath>
</template>
</odoo>
But this obviously does'nt work !
I'll appreciate any help on this :)
Thank you.
It's more easy than your code. Let me answer you properly as soon as I can. But my answer will be based on what it's done on the module web_widget_color if you wanna see it first
@Axel Mendoza : Thank you for the reply.
I gave a look to web_widget_color module's code, but it doesn't seem to be what i'm looking for ..., i'm surely missing something i guess.
I tried to override _check_visibility function and altering "this.$el.toggleClass('o_form_invisible',true);" but it only makes the value invisible, not the label :/