You need to sign in to do that
Don't have an account?

Disable paste function for a inputText field in a VF page.
Hi All,
I have a inputText field in a VF page and I need to disable paste function(Ctrl+v and paste using mouse button) so that we need to compulsorily type in the text box instead of just copy pasting.
I have tried the following script:
<script> function DisableCtrlKey(e) { var code = (document.all) ? event.keyCode:e.which; // look for CTRL key press if (parseInt(code)==17) { alert("Please re-type your email address"); window.event.returnValue = false; } } function DisableRightClick(event) { //For mouse right click if (event.button==2) { alert("Please re-type your email address"); } } </script>
and under the VF page:
<apex:inputText id="confirmemail" value="{!email}" onKeyDown="return DisableCtrlKey(event)" onMouseDown="DisableRightClick(event)" </apex:inputText>
It works fine but I want to implement the same functionality without using alert function.
Can anyone please let me know any work around to accomplish the above scenario.
Any help on this will be highly appreciated.
This is a bit vintage and uses jQuery, but it's a pretty nice reference for disabling copy/paste - http://www.4guysfromrolla.com/articles/060910-1.aspx
All Answers
This is a bit vintage and uses jQuery, but it's a pretty nice reference for disabling copy/paste - http://www.4guysfromrolla.com/articles/060910-1.aspx
This is more a browser question than a VF question. The problem is that not all browsers support the events that are required, e.g, the following works for some but not all browsers:
Most solutions I've seen involve 10s of lines of javascript to replicate the ondrop/onpaste events for browsers that don't support them. I'd go along with Tom's suggestion and use a JQuery solution.
Hi Tom and Bob,
That worked for me. Thanks.
Now another issue come up i.e., If we drag the text from a textbox to the confirm email textbox then the text is being copied.
I need to disable the drag and drop functionality for the textbox. I searched in the net nut nothing worked for me.
If possible could you/anyone please let me know how to disable drag and drop functionality for the textbox.
Thanks in Advance.
I know it was very old post, however I also faced this situation, i tried with following script, it's working for me. It may help someone in future!!
disable paste function and autocompletion directly on VisualForce :
Here an exemple :
<apex:inputText value="{!emailConfirmation}" html-onpaste="return false;" html-autocomplete="off" html-placeholder="Confirmez votre e-mail" styleClass="inputs" html-type="Email" />
best regards
Lynda,
How do you put your code on say the the Case Console Page?
Kind regards,
Robert