Skip to content

[19.0][IMP] web_m2x_options: color_style option - #3697

Open
mdurepos wants to merge 2 commits into
OCA:19.0from
bemade:19.0-imp-web_m2x_options-color_style
Open

mdurepos wants to merge 2 commits into
OCA:19.0from
bemade:19.0-imp-web_m2x_options-color_style

Conversation

@mdurepos

@mdurepos mdurepos commented Oct 7, 2026

Copy link
Copy Markdown

Depends on #3696. It contains that PR's commit; only the last commit is new here.

field_color colours the suggestion text. In practice that gives poor contrast, and a fixed CSS colour cannot suit both the light and the dark theme.

This adds a color_style option:

  • text (the default, or no option at all): exactly the current behaviour, color:<value>.
  • bar: a thin accent bar on the left of each suggestion (an inset box-shadow, so there is no layout shift). The text is left alone.

With bar, Bootstrap theme colour names (primary, secondary, success, info, warning, danger, light, dark) resolve through Odoo's theme CSS variables. Odoo compiles Bootstrap without the bs- prefix, so these are --success etc., and they are defined with different values in web.assets_web and web.assets_web_dark, so the bar follows the theme. Any other value is used as a CSS colour.

<field name="partner_id" options="{'field_color': 'type', 'color_style': 'bar',
       'colors': {'contact': 'success', 'invoice': 'warning', 'delivery': 'info'}}"/>

Supported on many2one and many2many tags, like field_color. Documented in readme/USAGE.md.

Tests: one checks that color_style: 'text' keeps the current output. The other checks the bar style for a theme name and a raw colour, and asserts the computed box-shadow actually resolves, so an undefined variable cannot pass silently.

🤖 Generated with Claude Code

mdurepos and others added 2 commits October 6, 2026 21:58
The field_color/colors options had no effect on many2one fields in 19.0:

- Many2OneField.m2oProps and the computeM2OProps override forwarded
  searchLimit but not fieldColor/fieldColorOptions, so the options never
  reached Many2XAutocomplete; Many2One did not declare them either.
- loadOptionsSource matched suggestions on option.value, which 19.0
  suggestions no longer have: the record is in option.data.record.

Adds a hoot test covering the dropdown colouring.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a color_style option next to field_color/colors. "text" (the
default) keeps the current text colouring unchanged. "bar" draws a thin
accent bar on the left of each suggestion and leaves the text alone, so
contrast does not suffer in either theme.

With "bar", Bootstrap theme colour names (success, info, warning, ...)
resolve through Odoo's theme CSS variables and so follow the light or dark
theme; any other value is used as a CSS colour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants