[英]Disable copy/past functionality in simple_form
I'm trying to disable the copy/paste functionality in the input field of a simple_form. 我正在尝试在simple_form的输入字段中禁用复制/粘贴功能。 I understand this has been asked before outside of a simple_form context.
我知道在 simple_form上下文之外已经问过这个问题。 I added a class to the form itself following the ideas from this post, and used that class within a function in application.js.
我按照这篇文章的想法在表单中添加了一个类,并在application.js的函数中使用了该类。 This is currently not producing the desired functionality--is there an idiosyncratic way to do this in simple_form?
这目前还没有产生所需的功能 - 在simple_form中有一种特殊的方法吗?
(I understand it's not recommended to tamper with default browser functionality, but the action of copying 'by hand' would jibe with what I'm trying to achieve with my app). (我知道不建议篡改默认的浏览器功能,但是“手动”复制的操作会与我试图通过我的应用程序实现的目标相吻合)。
In the view: 在视图中:
<%= simple_form_for @word, url: lesson_word_exposition_path(current_lesson, @word.word), html: { class: "disablecopypaste"}, method: :patch do |f| %>
<%= f.input :term_given_by_student, label: "Enter the term exactly as above:" %><br>
<%= f.button :submit, class: 'btn btn-primary' %>
<% end %>
From application.js: 来自application.js:
$(document).ready(function () {
$('input.disablecopypaste').bind('copy paste', function (e) {
e.preventDefault();
});
});
You could try using the user-select css property. 您可以尝试使用user-select css属性。
.unselectable : {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
$(document).ready(function () {
$('input.disablecopypaste').toggleClass('unselectable')
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.