跳至内容
菜单
此问题已终结
3 回复
3384 查看

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.



形象
丢弃
最佳答案
 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"); 
}  


形象
丢弃
最佳答案

Need to use options

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

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


形象
丢弃
编写者 最佳答案

The Post isn't displayed correctly.

The template is as follows:

     

The culprit is the "height" attribute and value.

形象
丢弃
相关帖文 回复 查看 活动
0
12月 23
929
1
6月 23
5165
0
3月 20
3077
0
3月 15
5260
0
3月 25
1172