首页 > 解决方案 > 如何禁用附件表单视图odoo11中的清除按钮?

问题描述

我正在尝试禁用附件表单中的清除按钮。我认为这是 js 代码。我搜索了一些 js 代码,但没有找到。

这个问题的任何提示?

在此处输入图像描述

这是清除按钮的图像

标签: odooodoo-11

解决方案


如果您想在 Odoo 中删除整个二进制字段小部件的 Button,您可以“扩展”该小部件的 QWeb 模板,即:

<t t-name="FieldBinaryFile">
    <a t-if="widget.mode === 'readonly'" href="javascript:void(0)" class="o_form_uri"/>

    <div t-if="widget.mode !== 'readonly'" class="o_field_binary_file">
        <input type="text" class="o_input"
            readonly="readonly"
            t-att-name="widget.name"
            t-att-tabindex="widget.attrs.tabindex"
            t-att-autofocus="widget.attrs.autofocus"/>

        <button type="button" class="btn btn-sm btn-primary o_select_file_button" title="Select">Upload your file</button>
        <button type="button" class="btn btn-sm btn-default fa fa-pencil o_select_file_button" title="Select"/>
        <button type="button" class="btn btn-sm btn-default fa fa-trash-o o_clear_file_button" title="Clear"/>

        <span class="o_form_binary_progress">Uploading...</span>
        <t t-call="HiddenInputFile">
            <t t-set="fileupload_id" t-value="widget.fileupload_id"/>
            <t t-set="fileupload_style" t-translation="off">overflow-x: hidden</t>
        </t>
    </div>
</t>

您可以扩展 QWeb 模板,但必须将它们加载到 key 下的清单文件中qweb

xml 文件通常在 /static/src/xml 的模块中

<templates>
    <t t-name="web.FieldBinaryFile" t-extend="base.FieldBinaryFile">
        <t t-jquery="button[title='Clear']"
            t-operation="replace" />
    </t>
</templates>

和清单的一部分

{
    'name': 'remove button in binary widget',
    # and so on
    'depends': [
        'base',
    ],
    'qweb': [
        'static/src/xml/remove_button.xml'
    ],
    # and so on
}

推荐阅读