forms - odoo 如何在网站模板中设置选定的属性

标签 forms select odoo

我在 Odoo 中设置网站公式的选定属性时遇到了一些麻烦。

我在基础模型中有一些数据,这些数据显示在表单内的表格中。行显示正确,但选择字段的值设置不正确。它始终显示选择列表中的第一个值,而不是模型中保存的值。

    <t t-foreach="quote_lines" t-as="quote_line">               
    <tr>
       <td>
          <!--  public categories for a selection field -->
          <select t-attf-name="supplier_{{quote_line.line}}">
             <t t-foreach="categories" t-as="c">
                <t t-if="c.name==quote_line.supplier"><option t-field="c.name" selected="selected" /></t>
                <t t-if="c.name!=quote_line.supplier"><option t-field="c.name" /></t>
             </t>
          </select>
        </td>
        ....
    </tr>
    </t>

表单已加载到 odoo 中并显示正常 - 除了 - 标签忽略我选择的属性。当我查看生成的 html 时,会设置选择/选项值,只是忽略此属性。

有什么提示我做错了什么或者只是没有看到吗?

最佳答案

尝试使用selected="True"

此外,请查看 website_sale 在各个国家/地区的表现:

              <div t-attf-class="form-group #{error.get('shipping_country_id') and 'has-error' or ''} col-lg-6">
                  <label class="control-label" for="shipping_country_id">Country</label>
                  <select name="shipping_country_id" class="form-control" t-att-disabled="  'disabled' if shipping_id &gt;= 0 else ''">
                      <option value="">Country...</option>
                      <t t-foreach="countries or []" t-as="country">
                          <option t-att-value="country.id" t-att-selected="country.id == checkout.get('shipping_country_id')"><t t-esc="country.name"/></option>
                      </t>
                  </select>
              </div>

https://github.com/odoo/odoo/blob/9.0/addons/website_sale/views/templates.xml#L1072-L1080

关于forms - odoo 如何在网站模板中设置选定的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33098914/

相关文章:

python - 如何在表单中多次使用同一字段?

python - res.partner 上 `write` 的高级访问权限

python - 如何防止 Odoo 中已分配日期的字段值重复?

android - 在 Delphi XE7 中的 Android 上第二次打开表单时出现访问冲突

javascript - 使用计算值预填充表单默认值

html - 动态更改输入文本框的字体大小以填充尺寸

mysql - 根据表中id的日期选择数据

jquery - 如果 "No Results Match"带有 .select,如何保存自定义选项?

HTML 表单 - 是否需要名称和 ID?

mysql - 如何查询从上个月到12个月前的记录?