Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
3794 Переглядів

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

Аватар
Відмінити
Найкраща відповідь

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
}



Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
січ. 23
1862
1
черв. 25
3918
2
трав. 24
1558
2
лют. 22
5144
1
вер. 19
10773