Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
3418 Lượt xem

Hello,

we extended a Model with an additional Image field:

class ProductTemplate(models.Model):
_inherit = 'product.template'
img = fields.Image(string="Image")

Now, when we want to display the image, we add the corresponding form view:

(Odoo doesn't correctly display xml, so i substituted < with (tag open) and > with (tag close))

(tag open) xpath expr="//field[@name='template_name']" position="after" (tag close)

      (tag open) field name="img" colspan="2" widget="image" height="'250'" / (tag close)

(tag open)/xpath(tag close)


     


     


Finally when we want to actually display the form view, following error is thrown:

UncaughtPromiseError > OwlError
Uncaught Promise > Invalid props for component 'ImageField': 'height' is not a number
OwlError: Invalid props for component 'ImageField': 'height' is not a number
    OwlError@http://<>/web/assets/776-1aebd68/web.assets_common.min.js:1133:1
    validateProps@http://<>/web/assets/776-1aebd68/web.assets_common.min.js:1586:67
    template@http:// Function:17:13

When "height= ... " is removed as attribute from the field tag in the template, everything works (without correct height of course).

I even dug into the Odoo source and found that height is fully supported: 

(Remove white spaces, I dont have enough karma for links)

https://github.com/odoo/odoo/blob/92c232cca15517bd9a33a5100e7cdc42c3c25397/addons/web/static/src/views/fields/image/image_field.js#L131C45-L131C45

And props declaration should work this way, if this document is correct: https://github.com/odoo/owl/blob/master/doc/reference/props.md

So why the fuck is this error thrown? Doesn't matter if I set height=250, height="250" or height='250' ... Odoo isn't recognizing the number 250 as a Number.



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
 Try debugging the type of that height is being passed to component, hope it helps to get it fixed 

// Add this logging line 
console.log("ImageField height:", props.height); 
 const height = props.height || 150; // Example default value 
 if (typeof height !== "number") {
 throw new OwlError("Invalid props for component 'ImageField': 'height' is not a number"); 
}  


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Need to use options

like this:  options="{'size': [0, 50]}"

Ex: <field name="logo" widget="image" options="{'size': [0, 50]}"/>


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

The Post isn't displayed correctly.

The template is as follows:

     

The culprit is the "height" attribute and value.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 12 23
931
1
thg 6 23
5225
0
thg 3 20
3087
0
thg 3 15
5261
0
thg 3 25
1182