2016-06-29 3 views
1

simple_formの入力フィールドでコピー/ペースト機能を無効にしようとしています。私はこれがシンプルフォームのコンテキストの外側にbeforeと尋ねられたことを理解しています。私はthisポストのアイデアに従ってフォーム自体にクラスを追加し、そのクラスをapplication.js内の関数内で使用しました。これは現在、目的の機能を生成していません - simple_formでこれを行うには特有の方法がありますか?simple_formでコピー/過去の機能を無効にする

(私は、デフォルトのブラウザ機能を改ざんすることはお勧めしませんが、「手作業でコピーする」というアクションは、私のアプリで達成しようとしているものに悩まされます)。ビューで

<%= 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 %> 

application.jsから:

$(document).ready(function() { 
    $('input.disablecopypaste').bind('copy paste', function (e) { 
     e.preventDefault(); 
    }); 
    }); 

答えて

3

あなたはユーザー選択CSSプロパティを使用して試みることができます。

.unselectable : { 
    -webkit-user-select: none; 
    -moz-user-select: none;  
    -ms-user-select: none;  
    user-select: none;   
} 


$(document).ready(function() { 
    $('input.disablecopypaste').toggleClass('unselectable') 
    }); 
関連する問題