How can I copy and paste on a screen?

0

Personal greetings,

I have a generic javascript util.js file with a function to not allow copy and paste.

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

On a specific page, I need a given field to copy and paste, and I did not want to get rid of util.js that it does not allow on other pages of the application. Is there any way to allow paste? Or turn off this validation for the specific page?

Thank you

Edit1: I called the unbind () method; right on the page that way and it worked

    $(document).ready(function() {

    $("input").unbind();

However, it works for all inputs on the screen. I tried to pass the id / field name as a parameter but it did not work. Ideally, only one field would allow copying and pasting.

Thank you in advance

Edit2:

The field that needs to allow copy and paste is this:

<td width="306" align="center">
                                <s:textfield id="idDesc%{#rowStatus.index}" cssClass="bg_input txtTable" cssStyle="%{listDespRec[#rowStatus.index].listError[2].aplicarCss}" name="listDespRec[%{#rowStatus.index}].observacaoLancamento" value="%{listDespRec[#rowStatus.index].observacaoLancamento}" size="35"  maxlength="30"/>
</td>

Any suggestions on how to pass this field on unbind?

This way it is not working here

$(document).ready(function() {

    $('#listDespRec[%{#rowStatus.index}].observacaoLancamento').unbind('copy paste');
    
asked by anonymous 19.07.2018 / 20:25

2 answers

1

Solution do the unbind for specific input.

Example:

$( "#foo" ).bind( "click", handler );
$( "#foo" ).unbind( "click", handler );

Practical example

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

$('#permitecopiar').unbind('copy paste');
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script><form>Nãopermitecolar:<inputtype="text"><br> Permite colar: <input id="permitecopiar" type="text"><br>
</form>
    
19.07.2018 / 21:53
0

Dude, if I understood correctly, would it be okay?

// Não permitir o copy/paste
$('input').bind('copy paste', (e) => false);

// Permitir
$('.copy_paste_on').unbind('copy paste');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputplaceholder="campo 1">
<input class="copy_paste_on" placeholder="campo 2">
<input placeholder="campo 3">

In your example it is not working because it is missing to tell you what kind of unbind follows unbind example:

.unbind( eventType [, handler ] )
    
19.07.2018 / 22:18