Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
2675 Tampilan

Hello,

When I customize my module, I need to override "SettingsBlock" properties (props). More details, the original code is:

===

SettingsBlock.props = {

    title: { type: String, optional: 1 },

    tip: { type: String, optional: 1 },

    slots: Object,

    class: { type: String, optional: 1 },

};

===

in (web/static/src/webclient/settings_form_view/settings/settings_block.js).

I just want to modify "slots" value (just it). There 2 potential solutions (I think):


1. Create new js in my module and then override entirely SettingsBlock.props, looks like that:

===

SettingsBlock.props = {
...SettingsBlock.props,
slots: { type: Object, optional: 1 },
}

===


2. Use "patch" to avoid all impacts to code base (recommended). However, I don't know how to use. 


Please help. Many thanks.




Avatar
Buang
Jawaban Terbai

The slots like that has it own purpose, i'm guessing you have messed with res.config.setting inheritance and you need to that. Trust me, i have encountered with this when my team somehow mess up with xml of res.config.setting inherit, some of them try to invisible wrong element so it caused error something like "slots bla bla"

Avatar
Buang
Jawaban Terbai

Hi,

We can use the patching method to override a function without changing the source code.For example, use the below code as a reference:

/** @odoo-module **/

import { SettingsBlock } from "@web/webclient/settings/settings_block";

import { patch } from "@web/core/utils/patch";


patch(SettingsBlock.prototype, {    async setup() {

        super.setup(); // By using the super function, we can execute all parent functions along with ours.

    },    settings_block(value){        // you can write your logic here    }

});


Hope it helps.

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Jun 24
1459
1
Mei 24
1957
1
Agu 23
2833
2
Nov 24
2299
2
Jul 25
435