Skip to content

[19.0][IMP] web_m2x_options: fix field_color, add color_style and field_icon - #3698

Open
mdurepos wants to merge 3 commits into
OCA:19.0from
bemade:19.0-imp-web_m2x_options-field_icon
Open

mdurepos wants to merge 3 commits into
OCA:19.0from
bemade:19.0-imp-web_m2x_options-field_icon

Conversation

@mdurepos

@mdurepos mdurepos commented Oct 7, 2026 •

Copy link
Copy Markdown

This PR now carries all three commits, rebased on 19.0, so they can be reviewed together. It supersedes #3696 (field_color fix) and #3697 (color_style), which are closed. Each commit stands on its own:

  1. [FIX] web_m2x_options: field_color on 19.0
  2. [IMP] web_m2x_options: color_style option
  3. [IMP] web_m2x_options: field_icon option

1. Fix field_color on 19.0

On 19.0 the field_color / colors options have no effect on many2one fields: suggestions are never coloured.

Two independent causes:

  1. The options never reach the dropdown. Many2OneField.m2oProps and the computeM2OProps override forward searchLimit but not fieldColor / fieldColorOptions, and Many2One does not declare them, so Many2XAutocomplete never receives them.
  2. Suggestions are matched on option.value, which 19.0 suggestions no longer carry: the record is in option.data.record. The search_read then gets no ids and nothing is coloured. "Search More" / "Create" entries have no record and are now skipped.

The module's template patch that applies option.style was already correct.

2. color_style option

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'}}"/>

3. field_icon option

Colour alone needs a legend. An icon per value can be read at a glance, e.g. telling contacts from delivery and invoice addresses in a long partner list.

This adds field_icon / icons, mirroring field_color / colors:

<field name="partner_id" options="{'field_icon': 'type',
       'icons': {'contact': 'fa-user', 'delivery': 'fa-truck', 'invoice': 'fa-money'}}"/>
  • icons maps a value of field_icon to a Font Awesome class. The icon renders as a fixed-width, muted <i aria-hidden="true"> before the label.
  • Values without an entry get no icon. Without the options, nothing changes.
  • It works alone or together with field_color / color_style. Both fields are fetched in the same search_read.

The nested option/record matching loop is replaced with an id lookup. That keeps eslint's max-depth happy now that there are two things to apply per record.

color_style and field_icon are supported on many2one and many2many tags, like field_color, and documented in readme/USAGE.md.

Rebase notes

19.0 has since gained the field-level create / create_edit overrides (m2xOverrideProps). The conflicts were purely additive: the override props and the colour/icon props are now declared and forwarded side by side, and the quick-create check keeps the override test.

Tests

tests/test_js.py runs the hoot suites:

  • static/tests/field_color.test.js: suggestions are coloured by field_color (fails before commit 1, passes after); color_style: 'text' keeps the current output; bar draws the accent bar for a theme name and a raw colour, asserting the computed box-shadow actually resolves so an undefined variable cannot pass silently.
  • static/tests/field_icon.test.js: mapped values get their icon, unmapped values get none, and no icon appears without the option.

🤖 Generated with Claude Code

@CRogos CRogos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdurepos could you rebase and solve the conflicts.

Also make sure to use Assisted-by: instead of Co-Authored-By: in the commit message. (In this and all other AI generated PRs)

I also think you should close the other two PRs and we review everything in this PR?

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.

Assisted-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.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
Adds field_icon/icons options, mirroring field_color/colors: icons maps
a value of field_icon to a Font Awesome class, shown as a fixed-width
muted icon on the left of each suggestion. Values without an entry get
no icon, and the colour and icon fields are fetched in the same request.

Also replaces the nested option/record loop with an id lookup.

Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
@mdurepos
mdurepos force-pushed the 19.0-imp-web_m2x_options-field_icon branch from afae4e8 to 45bcf96 Compare November 21, 2026 15:59
@mdurepos mdurepos changed the title [19.0][IMP] web_m2x_options: field_icon option [19.0][IMP] web_m2x_options: fix field_color, add color_style and field_icon Nov 21, 2026
@mdurepos

Copy link
Copy Markdown
Author

@CRogos thanks for the review. Done:

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.

3 participants