Skip to Content
मेन्यू
This question has been flagged
3 Replies
3407 Views

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.



Avatar
Discard
Best Answer
 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"); 
}  


Avatar
Discard
Best Answer

Need to use options

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

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


Avatar
Discard
Author Best Answer

The Post isn't displayed correctly.

The template is as follows:

     

The culprit is the "height" attribute and value.

Avatar
Discard
Related Posts Replies Views Activity
0
दिस॰ 23
930
1
जून 23
5219
0
मार्च 20
3078
0
मार्च 15
5261
0
मार्च 25
1182