Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
2 Antworten
3788 Ansichten

hi everyone how can i call a field values in file js odoo 15 please i need help

Avatar
Verwerfen
Beste Antwort

In Odoo 15, you can call a field value in a JavaScript file by using the instance.web.form.FieldChar or instance.web.form.FieldSelection class, depending on the type of field you want to call.

For example, if you want to call the value of a Char field named "field_name", you can use the following code:

var field_value = instance.web.form.FieldChar.extend({
init: function () {
this._super.apply(this, arguments);
this.field_value = this.get_value();
},
});

And if you want to call the value of a Selection field named "field_name", you can use the following code

var field_value = instance.web.form.FieldSelection.extend({
    init: function () {
        this._super.apply(this, arguments);
        this.field_value = this.get_value();
    },
});


You can then use the field_value variable to access the value of the field in your JavaScript code. It's also important to note that you will have to import the 'web.form_common' module first in your file.


odoo.define('module_name', function (require) {
"use strict";
var form_common = require('web.form_common');
// your code here
}



Avatar
Verwerfen
Beste Antwort

Hey there,

Could you elaborate your answer ?

=> you say "if your field is called field_name", but you actually don't use "field_name" anywhere.

=> you import "web.form_common", but you don't use your variable "form_common" anywhere !

=> you use "instance.web.[...]", but "instance" of what exactly ? Used like, this, the browser won't understand "instance" which is undefined.

Thank you

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
Jan. 23
1858
1
Juni 25
3898
2
Mai 24
1555
2
Feb. 22
5142
1
Sept. 19
10769