İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

How to Run JavaScript Inside HTML Fields in Odoo 17?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
javascriptwizardodoo 17
2 Cevaplar
3274 Görünümler
Avatar
Jacky

Hi everyone,

I'm trying to include JavaScript inside an HTML field in Odoo 17, but the script doesn't seem to execute. Here's the code I'm working with:

Copy code

html_field = fields.HTML("HTML Data", sanitize=False, compute="_compute_html") def _compute_html(self): self.html_field = """<script>console.log('TEST')</script>"""

The HTML field is defined as a computed field, and I have set sanitize=False to allow raw HTML. However, when I load the view, the JavaScript inside the <script> tag does not run.

The reason I need this is to call a modal or wizard dynamically in my custom form template. The data for the form is fetched using custom logic with PostgreSQL queries, so I was hoping to inject the JavaScript for triggering the modal or wizard directly into the HTML field.

Does Odoo block scripts in HTML fields by design? If so, how can I achieve this functionality? Is there a recommended way to include JavaScript for modals or wizards in custom templates while still leveraging Odoo's framework?

Any guidance would be greatly appreciated!

0
Avatar
Vazgeç
Avatar
Cybrosys Techno Solutions Pvt.Ltd
En İyi Yanıt

Hi,

Yes, Odoo blocks JavaScript execution inside HTML fields by design, even if you set sanitize=False. This is primarily for security reasons, to prevent XSS (Cross-Site Scripting) vulnerabilities.

Why <script> Doesn’t Work:


Even though you're using sanitize=False, Odoo’s rendering engine and modern browsers strip or ignore script tags in HTML fields for safety. This behavior is expected and intended.

Recommended Alternatives:


If you need to trigger modals or wizards dynamically, there are better and safer ways to do this in Odoo:

1. Use t-att-onclick or JS event binding in QWeb templates


Instead of injecting JS directly, attach an event handler to an element:


<button type="button" class="btn btn-primary" t-att-onclick="'trigger_modal(%d)' % record.id">Open Modal</button>


Then define the JS function trigger_modal() in your custom JS file loaded via assets.

2. Use @odoo-module JS to handle events


Create a custom JavaScript module that listens for button clicks and triggers a modal or action:


/** @odoo-module **/


import { Component } from "@odoo/owl";

import { registry } from "@web/core/registry";


class MyModalComponent extends Component {

    setup() {

        // modal logic here

    }

}


registry.category("actions").add("my_module.my_modal_action", MyModalComponent);


Then trigger it from Python or with do_action in JS.

3. Use do_action() in JS


If you're in a web context (e.g. custom JS), use:



this.do_action({

    type: 'ir.actions.act_window',

    res_model: 'your.model',

    view_mode: 'form',

    target: 'new',

});


This opens a wizard/modal cleanly and in line with Odoo standards.


While injecting JS into an HTML field might seem like a shortcut, it's not recommended and won’t work reliably in Odoo 17 due to built-in restrictions. Instead, use Odoo's JS framework and do_action() to build interactive features like modals or wizards.


Hope it helps

0
Avatar
Vazgeç
Avatar
Akhilesh N S
En İyi Yanıt

Even though you've set sanitize=False on the HTML field, Odoo may still be applying some additional sanitization or escaping to the HTML content, which could prevent the script from running

To achieve the functionality you're looking for, you can consider use of an Odoo Widget with JavaScript

You can find the example from module im_livechat

script_external = fields.Html( 'Script (external)' , compute = '_compute_script_external' , store = False , readonly = True , sanitize = False )

def _compute_script_external(self):
values = {
"dbname": self._cr.dbname,
}
for record in self:


values["channel_id"] = record.id
values["url"] = record.get_base_url()
record.script_external = self.env['ir.qweb']._render('im_livechat.external_loader', values) if record.id else False
<template id ="external_loader" name ="Livechat : external_script field of livechat channel" > 
<!-- the loader -->
<script t-attf-src ="{{url}}/im_livechat/loader/{{channel_id }}" type ="text/javascript" />
<!-- js of all the required lib (internal and external) -->
<script t-attf-src ="{{url}}/im_livechat/assets_embed.js " type ="text/javascript" />
</template>
0
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Open a wizard when clicking on "save" in a form in edit mode [Odoo 9]
javascript wizard odoo9
Avatar
0
Ağu 16
576
Unable to display CogMenuItem only in specific views
javascript views actions odoo 17
Avatar
0
Nis 25
1519
How can i inherit from the save button of a wizard at Odoo 17. Çözüldü
wizard inheritance leaves odoo 17
Avatar
Avatar
1
Eyl 25
1831
Widget to many2many widget
javascript wizard many2many many2many_tags
Avatar
0
Mar 21
3743
How to call a wizard from a systray button in Odoo 12? Çözüldü
javascript wizard odoo12.0 systray
Avatar
Avatar
1
Ağu 19
6828
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now