Author: |
TKO, Odoo S.A., Odoo Community Association (OCA) |
License: |
LGPL-3 |
Branch: |
10.0-dev |
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,
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)
@api.model
def _list_all_models(self):
self._cr.execute("SELECT model, name FROM ir_model ORDER BY name")
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="field-selector"</li>
<li>Using attrs set field read-only until the model is selected like,</li>
</ol>
<pre>
<code lang="xml"><field name="fax" position="attributes">
<attribute name="widget">field-selector</attribute>
<attribute name="attrs">{'readonly': [('model_id','=', False)]}</attribute>
<attribute name="data_model_field">model_id</attribute>
</field></code>
</pre>