Jump to content

How to disable pasting in a edit box


Recommended Posts

I don't think any of those codes are what he is looking for. He wants it so that you can still edit in a text box, but just can't paste in it. This can be achieved by comparing the lengths of the text box with the old text and the new text.

I have tested this code, and it seemed to be working just fine.

local textBox = guiCreateEdit ( 100, 100, 200, 40, "Some Sample Text", false ); 
  
addEventHandler ( "onClientGUIChanged", textBox, function ( ) 
    local oldText = getElementData ( source, "guiEdit:oldTextString" ); 
    local text = guiGetText ( source ); 
    if ( not oldText ) then 
        setElementData ( source, "guiEdit:oldTextString", text ) 
        return false; 
    end  
    if ( string.len ( text ) > string.len ( oldText ) ) then  
        if ( string.len ( text ) - string.len ( oldText ) > 1 ) then  
            guiSetText ( source, oldText ); 
            outputChatBox ( "Pasting is not allowed!" ); 
            return 
        end  
    end 
     
    setElementData ( source, "guiEdit:oldTextString", text ); 
end ); 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...