STAR TREK 2d20
  1. #1

    setSelectionPosition() can't get to select text

    edit: solved! had to use the onChar() function instead of calling the function with onValueChanged()

    hey guys. i'm trying to get an autocomplete working for a search function and the autocomplete part is working, but i'm not getting an actual selection in the UI. my Debug pulls up numbers, i'm just not getting the selection so that the autocomplete is removed if one keeps typing.
    here's what i've got. is it the control? or am i missing a crucial step?


    Code:
                          <basicstring name="searchname">
    				<anchored position="insidetopleft" height="25">
    					<left anchor="center" offset="-80" />
    					<top offset="80" />
    					<right anchor="center" offset="80" />
    				</anchored>
    				<empty text="~NPC name~" />
    				<script>
    					function onInit()
    						LastCheck = 0;
    						LoopBreaker = true;
    					end
    					function onValueChanged()
    						local testText = Module.getModules();
    						local DataSourceCheck = window.npcdatasource.getValue();
    						local DBNPCs = DB.getChildren("npc");
    						local aAutoFill = {};
    -----------clipped irrelevant lines here ------						
    						if DataSourceCheck == 0 then
    							if #getValue() &gt; 2 then
    								DBAutocomplete();
    							end
    -----------clipped irrelevant lines here ------
    						end
    					end
    					function DBAutocomplete()
    						local DBNPCs = DB.getChildren("npc");
    						local aAutoFill = {};
    						for k,w in pairs(DBNPCs) do
    							local kDatabaseNode = DB.getChild("npc", k);
    							local s = DB.getValue(kDatabaseNode, "name", "");
    							if s ~= "" then
    								table.insert(aAutoFill, s);
    							end
    						end
    						Debug.console("getCursorPosition(), #getValue()", #getValue(), getCursorPosition());
    						if getCursorPosition() == #getValue() then
    							local Curser = getCursorPosition();
    							local AutoComplete = StringManager.autoComplete(aAutoFill, getValue(), true);
    							if AutoComplete then
    								Debug.console(AutoComplete);
    								if getValue() ~= "" then
    									local sNewValue = string.sub(getValue(), 1, getCursorPosition()-1) .. AutoComplete .. string.sub(getValue(), getCursorPosition());
    									currentType = getValue();
    									setValue(currentType .. AutoComplete);
    									setSelectionPosition(#getValue());
    									Debug.console("#getValue(), getCursorPosition(), #AutoComplete, getSelectionPosition()", #getValue(), getCursorPosition(), #AutoComplete, getSelectionPosition());
    								end
    							end
    						end
    					end
    					function endLoopBreaker()
    						LoopBreaker = true;
    					end
    				</script>
    			</basicstring>
    Last edited by pr6i6e6st; July 4th, 2020 at 21:53.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Product Walkthrough Playlist

Log in

Log in