Jump to content

How to disable pasting in a edit box


Recommended Posts

Posted
local UseText = edit:getText() 
addEventHandler("onClientGUIChanged", root, function() 
    if source ~= edit then return false end 
    edit:setText(UseText) 
end) 
  

To set text, use that

UseText = text 
edit:setText(UseText) 

Posted
guiSetEnabled

This is your answer.

this function it only enable/disable the GUI element

and he is asking about How to disable pasting in a edit box.

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted

What is wrong? It's the same as AriosJentu. His code disable writing in a edit box.

It won't let you paste nor write. But I think he means write. let's see

Posted

its not working i tryd this:

local UseText = guiGetText(add_item_price) 
addEventHandler("onClientGUIChanged", add_item_price, 
function() 
    if source ~= edit then return false end 
    guiSetText(add_item_price, UseText) 
end) 

Posted
  
local UseText = guiGetText(add_item_price) 
addEventHandler("onClientGUIChanged", add_item_price, 
function() 
    if source ~= add_item_price then return false end 
    guiSetText(add_item_price, UseText) 
end) 
  

Posted

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 ); 

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...