تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
3341 أدوات العرض

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
ديسمبر 23
926
1
يونيو 23
5130
0
مارس 20
3064
0
مارس 15
5257
0
مارس 25
1162