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!