Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
6 Odpowiedzi
6190 Widoki

Can I inherit a defined "ir.ui.view" by its id in JavaScript?

For example, given the following view, Can I modify the target_field of module.model_tree_view in javascript code, like if (model.condition){ $([name="target_field"]).hide()}. If so can you also provide some example codes please, Thank you.

<record model="ir.ui.view" id="module.model_tree_view">
<field name="name">Model List View</field>
<field name="model">module.model</field>
<field name="arch" type="xml">
<tree>
            <field name="target_field"/>
</tree>
</field>
</record>

Awatar
Odrzuć
Autor

attrs="{'invisible': [('state','=','close')]}" can only set read, edit and invisible. In some use cases, we may want to change the style of a specific element not just hide or show but more fancy way, that is why I ask for the way to do it in javascript instead of XML or python code.

ok got it

Autor

The question is exactly how to modify the javascript widget to a specific view id only.

Autor Najlepsza odpowiedź

Instead of modifying the view by its id, we can extend the view widget and add the new view to the view registry. Then, we can add the attribute, js_class to the view to apply the new changes. In this case, only your view with js_class name will have the extended features in it, other normal kanban (without the js_class) will remain the same as before.

In your js file,

let view_registry = require('web.view_registry');
let KanbanView = require('web.KanbanView');
let myKanBanView = KanbanView.extend(...)
view_registry.add('my_custom_kanban', myKanBanView);

In your xml file,

<kanban js_class="my_custom_kanban">...<kanban/>

Awatar
Odrzuć
Najlepsza odpowiedź

can you use something like,

attrs="{'invisible': 
[('state','=','close')]}"
Awatar
Odrzuć
Najlepsza odpowiedź

you could not apply jquery directly on fields because of the client architecture you define view in XML and client view rendering engine converts it to HTML which understood by the browser. 

On the top of it, the client has MVC architecture so data/model (your condition) and View (HTML element) are separated by the controller. 
but you can easily achieve your requirement by extending the javascript widget it has both data and view.

Awatar
Odrzuć