Garry's Mod Wiki

Revision Difference

DTextEntry:OnLoseFocus#551539

<title>DTextEntry:OnLoseFocus</title> <function name="OnLoseFocus" parent="DTextEntry" type="panelfunc"> <ispanel>yes</ispanel> <description>Called whenever the DTextEntry lose focus.</description> <realm>Client and Menu</realm> </function> <example> <code> local default = "Brick with bob"⤶ ⤶ local textentry = vgui.Create( "DTextEntry" ) textentry:SetText( default ) textentry.OnLoseFocus = function( self ) if self:GetValue() == "" then⤶ self:SetValue( default )⤶ ⤶ concommand.Add( "test_textentry_onlosefocus", function(ply)⤶ local frame = vgui.Create( "DFrame" ) frame:SetSize( 400, 200 ) frame:Center() frame:MakePopup()⤶ ⤶ local default = "Brick with bob"⤶ ⤶ local textentry = vgui.Create( "DTextEntry", frame )⤶ textentry:SetText( default )⤶ textentry:Dock( TOP )⤶ textentry.OnLoseFocus = function( self )⤶ if ( self:GetText() == "" ) then⤶ self:SetText( default )⤶ end⤶ end end⤶ </code> ⤶ end )⤶ </code> <output>DTextEntry value reset to default value if the text entered is empty.</output> </example>