禁用文本字段 odoo 13 上的复制粘贴 [英] Disable copy paste on text field odoo 13
本文介绍了禁用文本字段 odoo 13 上的复制粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本字段.
my_field = fields.Text()
我想使用 java 脚本或 python 从输入中禁用复制和粘贴(ctrl+c,ctrl+v).我该怎么做,谢谢.
I want to disable copying and paste(ctrl+c, ctrl+v) from intput with java script or python. How i can do it, thanks.
推荐答案
您可以扩展 FieldText
widget 并防止 copy
和 paste
事件.创建一个新的小部件并绑定事件,然后在文本字段上设置 widget
属性.
You can extend the FieldText
widget and prevent copy
and paste
events. Create a new widget and bind the events then set the widget
attribute on the text field.
示例:(模块名称为 stack_overflow
)
odoo.define('stack_overflow.actions', function (require) {
"use strict";
var basic_fields = require('web.basic_fields');
var registry = require('web.field_registry');
var no_copy_paste = basic_fields.FieldText.extend({
events: _.extend({}, basic_fields.FieldText.prototype.events, {
'copy': '_onCopyPaste',
'paste': '_onCopyPaste',
}),
_onCopyPaste: function(ev) {
ev.preventDefault();
alert("Copy/Paste Disabled!");
},
});
registry.add('no_copy_paste', no_copy_paste);
});
将 js 文件添加到 资产包:
Add the js file to an asset bundle:
<template id="assets_backend" name="stack_overflow assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/stack_overflow/static/src/js/actions.js"></script>
</xpath>
</template>
在文本字段上设置小部件属性:
Set the widget attribute on the text field:
<field name="description" widget="no_copy_paste" placeholder="Add a description..." />
这篇关于禁用文本字段 odoo 13 上的复制粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文