code
One widget, two names: code and ace are the same registered descriptor that swaps a plain textarea for a real Ace editor with syntax highlighting, dark mode, and careful save semantics.
| Technical name | code |
|---|---|
| Field types | text, html |
| Views | form |
| Also registered as | ace (same descriptor); sibling code_ir_ui_view for ir.ui.view arch editing (19.0) |
| Module | web, present in every Odoo database |
| Used in core | 3 occurrences across 2 modules: website, marketing_card |
| Versions | Odoo 20.0, Odoo 19.0, Odoo 18.0, Odoo 17.0, Odoo 16.0 |
| No-code setup | No. Studio's widget picker does not offer it; apply it in view XML |
| Alternatives | text, html, domain |
What the Ace Editor field does
What this means for your team
Supported options in Odoo 19
| Option | Type | What it does |
|---|---|---|
mode | string | Ace language mode for highlighting: python, xml, qweb, javascript, scss and friends. The component remaps xml to qweb internally. Unknown modes degrade to plain text.(default: qweb)(since Odoo 17.0) |
The mode list is Ace's, filtered by what Odoo ships. Practically useful values are python, xml (which becomes qweb), qweb, javascript, scss and css. An unknown mode does not error; the editor simply falls back to plain text coloring.
Working examples
Save-time commits and the widget's history
Version compatibility
| Version | Status | Notes |
|---|---|---|
| Odoo 20.0 | In development | Not released. Development branch adds a lineWrapping boolean option and migrates to the new props system. Re-verified after launch. |
| Odoo 19.0 | Verified | Verified against the shipped source. Adds the code_ir_ui_view sibling registration. |
| Odoo 18.0 | Verified | Same option, same dual registration, same types as 19.0. |
| Odoo 17.0 | Verified | Introduces the code alias, the mode option, the shared CodeEditor and html support. |
| Odoo 16.0 | Partial / changed | Registered only as ace, text fields only; loaded the Ace library and python, xml and qweb modes directly. |
Upgrade note. Views using widget="ace" keep working on every version, but standardize on code going forward; it is the name core uses in new views. Views written for 16.0 that relied on text-only support gain html support from 17.0 with no change needed.
What is changing in Odoo 20
Common problems and fixes
| Symptom | Cause and fix |
|---|---|
| widget="code" does nothing on Odoo 16 | The code alias arrived in 17.0; 16.0 only registered ace. Use widget="ace" on 16.0 views. |
| XML highlighting looks like QWeb | The component remaps mode xml to qweb by design; QWeb mode is Odoo's XML mode. Nothing to fix; directives simply get extra coloring. |
| onchange on the field does not fire while typing | The widget commits on save signals, not per keystroke, after comparing against the initial value. Expected; trigger logic on save, or use a plain text widget if per-keystroke reaction is essential. |
| Editor renders with a dark theme unexpectedly | The theme follows the color_scheme cookie: dark scheme loads monokai automatically. Switch the user's color scheme; there is no per-field theme option. |
| No highlighting for an exotic language | Only the modes Odoo ships with its Ace build are available; unknown modes fall back to plain text. Stick to python, qweb, javascript, scss or css, or add the mode file in a custom module. |
Ace Editor field vs the alternatives
| Widget | Best for | Key difference |
|---|---|---|
code | Text fields holding code, templates or markup | Full Ace editor with language modes and save-time commit semantics |
| text | Plain multi-line notes | Simple textarea, no highlighting, immediate standard field behavior |
| html | Rich content authored visually | WYSIWYG editor writing HTML, not a code surface |
| domain | Domain expressions specifically | Structured domain builder with count preview instead of raw text |
Frequently asked questions
What is the difference between widget="code" and widget="ace" in Odoo?+
Which languages can the code widget highlight?+
Does the code widget save on every keystroke?+
Can I use the code widget in Odoo Studio?+
What is code_ir_ui_view?+
What changes for the code widget in Odoo 20?+
Editing Odoo templates in a form field?
Custom website head code, QWeb report tweaks and expression fields are where quick edits quietly break production. We set up proper development workflows for Odoo teams, and build the custom views, widgets and editors that make in-house maintenance safe on Odoo 16 through 19.
Make my customizations safe