Mutex Toggle Field
by YLHC Technology https://www.ylhctec.com , co. https://www.ylhctec.com , ltd. https://www.ylhctec.com| Availability |
Odoo Online
Odoo.sh
On Premise
|
| Lines of code | 49 |
| Technical Name |
ylhc_mutex_toggle |
| License | LGPL-3 |
| Website | https://www.ylhctec.com |
Mutex Toggle Field
Mutually Exclusive Toggle Widget for Odoo List Views
Technical Widget Module
Ylhc Mutex Toggle Field provides a mutually exclusive toggle widget for boolean fields in Odoo list views. When enabled on a record, it automatically disables the toggle on all other records in the list, ensuring only one item can be active at a time. Perfect for selecting a default item, primary record, or exclusive option!
This widget extends Odoo's standard boolean toggle field with mutex (mutually exclusive) functionality. When you toggle a field ON in one record, the widget automatically sets the same field to OFF in all other records. This ensures only one record can have the toggle enabled at any given time - perfect for scenarios like "set as default", "is primary", "featured item", or "active selection".
Visit Our Website for More Information Contact Support: support@ylhctec.com
Usage Guide
Implementing the mutex toggle widget is simple and straightforward. Follow these steps to add mutually exclusive toggle functionality to your boolean fields:
Installation
- Navigate to Apps menu in Odoo
- Search for "Mutex Toggle Field"
- Click Install button
- Wait for installation to complete
Basic Usage
Add the widget to any boolean field in your list view XML:
<field name="is_default" widget="mutex_toggle"/>
Complete Example
Here's a complete example showing how to use the mutex toggle widget in a list view:
<odoo>
<record id="view_partner_bank_tree" model="ir.ui.view">
<field name="name">partner.bank.tree</field>
<field name="model">res.partner.bank</field>
<field name="arch" type="xml">
<tree>
<field name="acc_number"/>
<field name="bank_name"/>
<field name="is_default" widget="mutex_toggle"/>
</tree>
</field>
</record>
</odoo>
Common Use Cases
- Default Selection: Mark one item as the default (e.g., default bank account, default address)
- Primary Record: Designate a primary contact, primary phone number, etc.
- Featured Item: Highlight one featured product, article, or image
- Active Selection: Set one active configuration from multiple options
- Preferred Option: Choose preferred shipping method, payment method, etc.
- The widget only works in list/tree views
- All records must be loaded in the current list view for proper mutex behavior
- The widget patches Odoo's boolean toggle to prevent auto-save
- Works with standard Odoo boolean fields - no model modifications required
Key Features
Ylhc Mutex Toggle Field provides essential functionality for managing mutually exclusive boolean fields in Odoo list views. Simple, efficient, and developer-friendly.
Mutex Functionality
Automatic mutual exclusion - only one record can have the toggle enabled at a time.
Easy Integration
Simply add widget="mutex_toggle" to any boolean field - no model changes required.
List View Optimized
Designed specifically for Odoo list/tree views with seamless user experience.
Controlled Saving
Patches boolean toggle to prevent auto-save, giving you full control over when changes persist.
Clean Code
Well-structured, maintainable JavaScript code following Odoo best practices.
Lightweight
Minimal code footprint with no performance impact on your Odoo instance.
Odoo 18 Ready
Fully compatible with Odoo 18.0 and OWL 2.0 framework.
Developer Friendly
Simple API, clear documentation, and straightforward implementation.
Frequently Asked Questions
Do I need to modify my models to use this widget?
No! The mutex toggle widget works with standard Odoo boolean fields. No model modifications, custom fields, or database changes are required.
Does it work in form views?
The mutex toggle widget is specifically designed for list/tree views. In form views, it will behave as a standard boolean field.
What happens if I toggle a field ON?
When you enable a toggle, the widget automatically sets the same field to OFF in all other visible records in the list. Only one record will have the toggle enabled.
Can I use it on multiple fields?
Yes! You can use the mutex_toggle widget on multiple different boolean fields in the same view. Each field operates independently with its own mutex behavior.
Is it compatible with Odoo Community Edition?
Yes! The widget works perfectly with both Odoo Community and Enterprise editions for version 18.0.
Please log in to comment on this module