Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
3791 Weergaven

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

Avatar
Annuleer
Beste antwoord

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
Annuleer
Beste antwoord

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
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
jan. 23
1859
1
jun. 25
3914
2
mei 24
1556
2
feb. 22
5144
1
sep. 19
10772