Momo Momoretto
Momo Momoretto

Reputation: 89

Odoo 8 src variable for iframe in ir.ui.view

Model

class ItemStocks(models.Model):
    _name = 'item.stocks'

    item_url = fields.Char('View Item')
ItemStocks()

View

<record id="view_item_stocks_form" model="ir.ui.view">
    <field name="name">item.stocks.form</field>
    <field name="model">item.stocks</field>
    <field name="arch" type="xml">
        <form string="Item Stocks">
        ...
            <page string="Live Site">
                 <form string="Embedded Webpage" version="7.0" edit="false">
                      <iframe marginheight="0" marginwidth="0" frameborder="0"
                                        src="{Variable for this.item_url}" width="100%" height="1000"/>
                 </form>
            </page>
      ...
        </form>
    </field>
</record>

How can I replace {Variable for this.item_url} with a valid expression for the field in model? Is there a better way to do like this? What would you prefer to solve the requirement of showing dynamically an embedded webpage?

Context: Odoo 8, New Api, ir.ui.view

Upvotes: 3

Views: 1605

Answers (1)

Devangi Shinde
Devangi Shinde

Reputation: 141

  **`Image Url wise Set Dynamic Iframe In Odoo`**
# v11 odoo community
you need to create  fields like this :
image_url = fields.Char('Image Url')
img_attach = fields.Html('Image Html')


# set image_url in iframe
     @api.onchange('image_url')
     def onchange_image_url(self):
         if self.image_url:
             self.img_attach = '<img id="img" src="%s"/>' % self.image_url
# set image_url in form view 
     <field name="image_url" />
# after added script
        <script>
        if(document.getElementById("img")){
           var value= document.getElementById("img").src;
           document.getElementById("custom_src").src=value; 
         }
        </script>


# also set iframe in form view
      <iframe id="custom_src" src="" width="200" height="200"  />     

#output
show the image : https://i.sstatic.net/0x7et.png

Upvotes: 2

Related Questions