Many2many Website Forms Odoo 18
By Braincuber Team
Published on December 28, 2025
Developer building website contact forms creates user experience disaster: customer wants to select multiple product interests (Consulting/Development/Support) from dropdown but standard Odoo website forms only support single-selection fields, developer codes 3 separate checkbox fields requiring 15 lines of custom CSS for layout, JavaScript valation logic broken when user selects none causing form submission errors, backend receives 3 separate boolean fields instead of clean Many2many relationship requiring custom processing code converting booleans to tag IDs, and no visual pill display showing selected options before submission—creating cluttered forms and complex backend processing from lack of native Many2many field support in website forms.
Odoo 18 Many2many Website Forms enable multi-selection relationships through XML template inheritance extending default forms, multi-select dropdown rendering all available records, JavaScript widget managing tag selection as removable pills, real-time DOM synchronization between dropdown and pill display, backend controller processing selected IDs via ORM command, automatic partner categorization, and reusable pattern applicable to any Many2many field—reducing development time 80% while providing clean UX with visual feedback through pill-based tag selection eliminating complex checkbox layouts and manual relationship management.
Many2many Features: Multi-select dropdown, Visual pill display, Remove button on pills, DOM synchronization, ORM command processing, Template inheritance, JavaScript widget, Reusable pattern, Clean UX
Implementation Components
Three core files required for Many2many website forms:
- XML Template: Extends default website form with Many2many dropdown
- JavaScript Widget: Manages tag selection and pill display
- Python Controller: Processes submitted data and saves to database
XML Template - Form Extension
Extend the default contact us form with Many2many dropdown field.
JavaScript Widget - Tag Management
JavaScript widget manages tag selection creating visual pills with remove buttons.
Python Controller - Backend Processing
Python controller processes submitted tag IDs and saves to partner record using ORM commands.
Complete Workflow
- Controller loads all CRM tags from database
- Template renders dropdown with all tags
- JavaScript widget initializes
- User selects multiple tags from dropdown
- Pills appear showing selected tags with remove buttons
- Form submission sends selected IDs to controller
- Controller saves tags to partner record
Best Practices
Always Use ORM Replace Command: Using individual add commands = N database queries. Single replace command = 1 database query replacing all. Performance: 100 tags with individual adds = 100 queries (2000ms), single replace = 1 query (20ms) = 100x faster.
Add Visual Feedback During Tag Removal: Instant DOM removal without transition = jarring UX. Add CSS transition before removal. Pill fades out smoothly over 200ms then removed. Professional feel improving perceived performance quality.
Handle Empty Selection Validation: Allowing form submission with zero tags selected = incomplete data. Add JavaScript validation before form submission. Prevents backend receiving empty Many2many preventing data quality issues.
Conclusion
Odoo 18 Many2many Website Forms enable multi-selection relationships through XML template inheritance, JavaScript widget managing visual pill display, and backend ORM command processing. Reduce development time 80% providing clean UX with real-time visual feedback eliminating complex checkbox layouts through reusable pattern applicable to any Many2many field achieving professional multi-select forms with minimal code.
