DTextEntry autocomplete mucking up

It appears the DTextEntry only supports autocomplete partially.

Here’s some code:

[lua]
concommand.Add( “textentryautocomplete”, function()
local frame = vgui.Create( “DFrame” )
frame:SetSize( 500, 500 )
frame:Center()
frame:MakePopup()

local entry = frame:Add( "DTextEntry" )
entry:SetPos( 50, 50 )
entry:SetSize( 300, 300 )
entry.GetAutoComplete = function( pnl, txt )
	return { txt, "test", "test2" }
end

end )
[/lua]

You’ll see when you type in a message it will show as well as the other two options, but when clicking the options nothing happens.
By nothing I literally mean just that; it’s as if the click doesn’t register all.

I’ve narrowed it down to oddly enough the autocomplete will NOT register if the autocomplete box is inside the panels bounds at all. (including the parent frame)

Overriding the OpenAutoComplete function will prove this as well.

Have some more code:

[lua]
concommand.Add( “testfixquick”, function()
local frame = vgui.Create( “DFrame” )
frame:SetSize( 500, 500 )
frame:Center()
frame:MakePopup()

local entry = frame:Add( "DTextEntry" )
entry:SetPos( 50, 50 )
entry:SetSize( 300, 300 )
entry.GetAutoComplete = function( pnl, txt )
	return { txt, "test", "test2" }
end
entry.OpenAutoComplete = function( pnl, tab )

	if ( !tab ) then return end
	if ( #tab == 0 ) then return end

	pnl.Menu = DermaMenu()

	for k, v in pairs( tab ) do

		pnl.Menu:AddOption( v, function() print( v ) pnl:SetText( v ) pnl:SetCaretPos( v:len() ) pnl:RequestFocus() end )

	end

		-- commented out as this will break autocomplete
	--local x, y = pnl:LocalToScreen( 0, self:GetTall() )
	local x,y = 120, ScrH()/2
	pnl.Menu:SetMinimumWidth( pnl:GetWide() )
	pnl.Menu:Open( x, y, true, pnl ) 
	pnl.Menu:SetPos( x, y)
	pnl.Menu:SetMaxHeight( ( ScrH() - y ) - 10 )

end

end )
[/lua]

This will put the autocomplete box outside of the frame completely, which will register.

Have some screenshots:

Before clicking (code before change of position)

http://image.prntscr.com/image/4e67c33fad684ad8adaa14270b7e32a5.png[/t]

After clicking (code before change of position)
[t]http://image.prntscr.com/image/ce461e093a0e443ca07cfbf402631573.png[/t]

Before clicking (position change)
[t]http://image.prntscr.com/image/c038de5993644054a62273fcce4688f5.png[/t]

After clicking (position change)
[t]http://image.prntscr.com/image/33e4107f8a474e7682bf34abcb98267b.png

Help would be appreciated, thanks.

EDIT a friend has been nice enough to share a video using first example

Ok this is what causes it in this case:

Not sure what to do about this yet.

I’ve found a solution.

I edited the text entry’s OpenAutoComplete function to set the DMenu as the DTextEntry’s child.

New code:
[lua]
function PANEL:OpenAutoComplete( tab )

if ( !tab ) then return end
if ( #tab == 0 ) then return end

self.Menu = DermaMenu()
self.Menu:SetParent( self )

for k, v in pairs( tab ) do

	self.Menu:AddOption( v, function() self:SetText( v ) self:SetCaretPos( v:len() ) self:RequestFocus() end )

end

local x, y = self:LocalToScreen( 0, self:GetTall() )
self.Menu:SetMinimumWidth( self:GetWide() )
self.Menu:Open( x, y, true, self )
self.Menu:SetPos( x, y )
self.Menu:SetMaxHeight( ( ScrH() - y ) - 10 )

end
[/lua]

Then I had to edit the TextEntryLoseFocus function to check if the new panel being set focused on is a child of the DTextEntry

New code:

[lua]
function TextEntryLoseFocus( panel, mcode )

local pnl = vgui.GetKeyboardFocus()
if ( !pnl ) then return end
if ( pnl == panel ) then return end
if ( !pnl.m_bLoseFocusOnClickAway ) then return end
    if ( panel.GetParent and panel:GetParent() ) and ( pnl == panel:GetParent():GetParent():GetParent() ) then return end

pnl:FocusNext()

end
hook.Add( “VGUIMousePressed”, “TextEntryLoseFocus”, TextEntryLoseFocus )
[/lua]

Probably not the best way, but it’s what I’ve found and it works with no side effects (that I’ve seen so far)