PDA

View Full Version : Autofill in Input?


SiNisTer
08-11-2007, 10:16 AM
Guys, I want to do an Autofill in an input object based on the contents of a Listbox,
but cant seem to pull it through..Wonder if its possible, and if so how?
Any help or pointers would be appreciated!

Thanks in advance...

holtgrewe
08-16-2007, 08:14 AM
SiNisTer
This sounds doable. Post back a snippet of your code so someone can take a look at what problem you're having.

SiNisTer
08-17-2007, 03:39 AM
Hi holtgrewe,
I don't really have any code snippets yet at the moment, as it was just a thought in my head - I was actually looking for some ideas from some of you guys here, as base to start working on. I have a few ideas and I suppose that to begin with I should use a Table (from content in listbox) and string compare to compare the values (maybe on timer or on key of input)...havent really started yet but Im sure you and many others would agree that it would be pretty cool, and I do suppose that it is as you mentioned, doable in ams...
I am gonna start working on it soon, and I shall make sure to post back aright:yes

usernameCasper
08-17-2007, 03:50 AM
You mean populate text into object related to the listbox?
It can be done, you want it on show or on certain actions ?

Kind regards,
Casper

SiNisTer
08-17-2007, 04:14 AM
You mean populate text into object related to the listbox?
It can be done, you want it on show or on certain actions ?

Kind regards,
Casper

Yup - specifically what I have in mind is that when a user types into an input object, and if an instance of the text was found in listbox, it would do an autofiller - but not replace the whole text that the user has typed in, unless the user has clicked elsewhere (outside the input object for that matter), like in certain programs - I suppose windows explorer and certain browsers, and search engines would be a few examples...Hoped that was clear and wasn't confusing. Any ideas mate?

usernameCasper
08-17-2007, 05:31 AM
Hey mate,

See the attachment, it's done, it use one actionlistener in the input.
For some guys that have a competition mentallity, I want to hear some improvements in my work now, I think you have a hard one now, if you think you can make code in less lines, I will do it from now on too, make it harder for other programmers to get a better understanding, but some guys like to exceed others, I dont mind, you want official programming challenges, PM me please and we can settle that down, I'm not the "pro" in luacom or C++, I control most of the things in most languages, feel free to PM me.

Btw, toke me 2 min work for this, for those particulary persons...

Sorry mate, but had to give my vision about helping others>
Have fun !

-Casper

TJ_Tigger
08-17-2007, 10:17 AM
I did something similar with a SQL database. I ended up using two functions, one to build a table with the data and another to search for matching text.


--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
--%% looks up information in a table returned from a SQL query %%
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%

function TableLookup(strObject, tbInput)
-- Do I need to add a String.Lower function here for comparison?
local strInput = Input.GetText(strObject);
local strColumn = String.Mid(strObject, 3, -1);
nLength = String.Length(strInput);
if tbInput.Rows ~= 0 then
for i,v in tbInput.Data do
if strInput == String.Left(tbInput.Data[i][strColumn], nLength) then
strRemainder = String.Mid(tbInput.Data[i][strColumn], nLength + 1, -1);
strNewInput = strInput..strRemainder
Input.SetText(strObject, strNewInput);
Input.SetSelection(strObject, nLength+1, -1);
end
end
end
end

--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
--%% Builds a table of distinct information %%
--%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%

function BuildTable(strObject, strTable)
local strColumn = String.Mid(strObject, 3, -1);
local tbReturn = SQLite.QueryToTable(thsdb, "SELECT DISTINCT "..strColumn.." FROM "..strTable);
if tbReturn then
return tbReturn;
else
tbReturn = {};
tbReturn.Rows = 0;
tbReturn.Data = {};
tbReturn.Data[1] = {};
tbReturn.Data[1][strColumn] = "NULL"
return tbReturn;
end
end


And this went into the input On Focus action

strOldText = Input.GetText(this);
tbLookup = BuildTable(this, "Customers");

And this went into the input On Key action

if e_Key == 9 or e_Key == 13 then
CheckForUpdate(this, strOldText, blnUpdate);
elseif e_Key > 46 then
TableLookup(this, tbLookup);
end

There are other things going on with the code but what would happen is I would build a table of the distinct entries from the database and use that as the person typed to look for a match. If there was a match it would autocomplete and highlight the autofill text so the person could keep typing if they wanted or hit tab or enter.

HTH