Search 1.9 billion lines of Odoo code on GitHub

web_widget_field_selector

Author: TKO, Odoo S.A., Odoo Community Association (OCA)
License: LGPL-3
Branch: 10.0
Repository: thinkopensolutions/oca-web
Dependencies: web
Languages: JavaScript (1071, 82.2%), LESS (157, 12.0%), Python (20, 1.5%), XML (43, 3.3%), and reStructuredText (12, 0.9%)
Other branches: 10.0-dev, and web_widget_field_selector

<a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.svg"> </a> <a name="odoo-field-selector-widget"></a> <h2>Odoo Field Selector widget</h2> <a name="usage"></a> <h3>Usage</h3> <p>To use this module, you need to:</p> <blockquote> <ol class="arabic simple"> <li>define model_id selection field like below</li> <li>selection field populate with below function</li> </ol> </blockquote> <pre> <code lang="python">model_id = fields.Selection(selection='_list_all_models', string='Model', required=False) &#64;api.model def _list_all_models(self): self._cr.execute(&quot;SELECT model, name FROM ir_model ORDER BY name&quot;) return self._cr.fetchall()</code> </pre> <a name="to-use-this-field-in-view"></a> <h3>To use this field in view</h3> <ol class="arabic simple"> <li>Define the char field with widget=&quot;field-selector&quot;</li> <li>Using attrs set field read-only until the model is selected like,</li> </ol> <pre> <code lang="xml">&lt;field name=&quot;fax&quot; position=&quot;attributes&quot;&gt; &lt;attribute name=&quot;widget&quot;&gt;field-selector&lt;/attribute&gt; &lt;attribute name=&quot;attrs&quot;&gt;{'readonly': [('model_id','=', False)]}&lt;/attribute&gt; &lt;attribute name=&quot;data_model_field&quot;&gt;model_id&lt;/attribute&gt; &lt;/field&gt;</code> </pre>