Catching Primefaces form elements in jquery and preventing copy paste and cut operations

xhtml

<p:inputText id="firstName" placeholder="#{msg.member_name}"
								value="#{memberController.order.firstName}" size="30"
								maxlength="30" widgetVar="firstNameVar" required="true"
								styleClass="#{not component.valid ? 'ui-input-invalid default-input-text' : 'default-input-text'}"
								onkeypress="return disallowNonAlphabethCharacters(event);">
								<p:ajax delay="1000" event="keyup"
									oncomplete="rc([{name: 'component', value: ':primeForm:firstName'},
                        {name: 'widget', value: 'firstNameVar'}]);" />
							</p:inputText>

javascript

<script type="text/javascript">
				 $( document ).ready(function() {
					 PF('firstNameVar').jq.bind('cut copy paste', function(e) {
							e.preventDefault();
						});
					 
					 PF('firstNameVar').jq.bind("contextmenu", function(e) {
			                e.preventDefault();
			            });
				    });
					</script>

Leave a Reply

Your email address will not be published. Required fields are marked *