Page 1 of 1

Autocomplete Combobox

Posted: Sun May 25, 2014 6:50 pm
by fko
Hi,

It is amazing...I never spent so much time in front of my laptop with no other program as with LiveCode (since i discovered it around two weeks ago)...:-)
It is quite intuitive, and if not there is many many information and if not there it exists this nice forum...

So as my intuitionm didn't work this time and as i found no example to do this finally i decided to ask my question in the forum...:-)

I am trying to populate the column "name" of one table of my database in one combobox...And then the user can access to this combobox to choose one value...But as i have more than 50 rows it begin to be not practical pass one by one all the items to arrive till the choosen one...

So, i am trying to do one 'autocomplete'...But i don't know how to do this...:-(

regards,
fko

Re: Autocomplete Combobox

Posted: Sun May 25, 2014 11:32 pm
by jmburnod
Hi fko,
I think "filter" is the magic word in your case.
Best regards
Jean-Marc

Re: Autocomplete Combobox

Posted: Mon May 26, 2014 6:37 pm
by fko
Hi Jean-Marc

Thanks for your answer...

I looked in the dictionary and in the lessons of livecode but i didn't find how to use the filter you are telling me...

This is the part of my code that has relationship with the combobox:

put "SELECT Name FROM Users" into query
put revDataFromQuery(comma, return, tDatabaseID, query) into tTheComboBoxData
answer tTheComboBoxData
put tTheComboBoxData into button "TestCombo"

What should I do to use the filter you are telling me to reach the autocomplete in my combobox?

regards,
fko

Re: Autocomplete Combobox

Posted: Mon May 26, 2014 6:49 pm
by fko
It is me again...:-)

Reading my post i think that i expressed myself bad...

So of course that i found information about the command filter in the lessons of livecode...
But not how to use it with one combobox to reach the autocomplete...

regards,
fko

Re: Autocomplete Combobox

Posted: Mon May 26, 2014 10:51 pm
by jmburnod
Hi fko,
Have a look to the stack in attachment.
I hope it helps
Best regards
Jean-Marc

Re: Autocomplete Combobox

Posted: Tue May 27, 2014 12:18 pm
by fko
Hi Jean-Marc

Thanks for the example...:-)

I tried to adapt your code to my necessity...Because what i tryin is to make the autocomplete when the user is typing directly in the text field of the combo box

So, i made this:

on keyUp pKey
--put pKey after fld "fSearch"
put pKey after text of button "TestCombo"
doFilterList
end keyUp

on rawkeydown pRawKey
if pRawKey = 65288 then
--delete char -1 of fld "fSearch"
--delete char -1 of text of button "TestCombo" ***** THIS LINE I CAN'T ADD IT, BECAUSE I HAVE ONE ERROR...:-(
doFilterList
end if
end rawkeydown

on doFilterList
global tTheComboData
put the text of button "TestCombo" & "*" into tFilter
--put fld "fSearch" & "*" into tFilter
get tTheComboData
filter it with tFilter
set the label of btn "TestCombo" to line 1 of it
set the text of btn "TestCombo" to it
end doFilterList

Do you know why is not working?

regards,
fko

Re: Autocomplete Combobox

Posted: Tue May 27, 2014 12:24 pm
by fko
I forgot to add the function where i fill the combo

so it is this one:

global tTheComboData
databaseConnect
put getDatabaseID() into tDatabaseID
put "SELECT Name FROM Users" into query
put (revDataFromQuery(comma, return, tDatabaseID, query)) into tTheComboData
put tTheComboData into button "TestCombo"


So in "tTheComboData" i have all the values...This is like your "fonelist"

regards,
fko

Re: Autocomplete Combobox

Posted: Tue May 27, 2014 5:43 pm
by Klaus
Hi fko,

"the text of btn xyz" is the complete content (= all menu items!)!
but you need to check and use "the label of btn xyz"!

Try this:
fko wrote:

Code: Select all

on keyUp pKey
   ###put pKey after text of button "TestCombo"
   set the LABEL of btn "Testcombo" to (the LABEL of btn "Testcombo" & pKey)
   doFilterList
end keyUp

Code: Select all

on rawkeydown pRawKey
   if pRawKey = 65288 then
      --delete char -1 of text of button "TestCombo"   ***** THIS LINE I CAN'T ADD IT, BECAUSE I HAVE ONE ERROR...:-(
     ## See above...
      doFilterList
   end if
end rawkeydown

Code: Select all

on doFilterList
   global tTheComboData
   ##put the text of button "TestCombo" & "*" into tFilter
   put the LABEL of button "TestCombo" & "*" into tFilter
   get tTheComboData
   filter  it with tFilter
   set the label of btn "TestCombo" to line 1 of it
   
   ## This will overwrite the content of that button!
   ## Is that what you want?
   ###set the text of btn "TestCombo" to it 
end doFilterList
Best

Klaus

Re: Autocomplete Combobox

Posted: Wed May 28, 2014 7:21 am
by fko
Hi Klaus,

Thanks for your help...:-)

I think this exactly what i want...:.-)
I made one test and it works fine!!!

Later i will continue to test more things...But yes, it is working well!!! :-)

regards,
fko

Re: Autocomplete Combobox

Posted: Wed May 28, 2014 12:25 pm
by Klaus
Hi fko,

important hint: Do not use IT more than ONCE or at all if not neccessary!
It will change ITs content when you least exspect IT! :D

Instead of:
...
put the LABEL of button "TestCombo" & "*" into tFilter
get tTheComboData
filter it with tFilter
set the label of btn "TestCombo" to line 1 of it
...
use a VARIABLE:
...
put the LABEL of button "TestCombo" & "*" into tFilter
put tTheComboData into tCD2
filter tCD2 with tFilter
set the label of btn "TestCombo" to line 1 of tCD2
## etc...
...

Best

Klaus

Re: Autocomplete Combobox

Posted: Wed May 28, 2014 6:22 pm
by fko
Hi Klaus,

Thanks for your correction...:-)

I saw your message 5 minutes ago...And i just changed it now...:-)

Anyway for the the code you sent me before i had one line that i told i didn't manage to include it...
And you made me notice that i should change 'the label' instead of 'the text' of the "TestCombo"...

But anyway it is not working like this...:-(

i have this error:

button "TestCombo": compilation error at line 16 (Commands: missing ',') near "of", char 20

So this is my code:

on rawkeydown pRawKey
if pRawKey = 65288 then
delete char -1 of( the label of button "TestCombo")
doFilterList
end if
end rawkeydown

So finally i decided to comment the line od 'delete' and i have no problems

And i have one doubt also....Is it because i commented this line that when i write in the label of the comboBox i can write only one letter?

What i am trying to do with the autocomplete is to search in the combo during i am writing...So if i am looking for 'John' i would like to Write 'J' and then 'O' after, etc... So have "J" the "JO", then "JOH", etc...
But for the moment if press on the first key ('J') i see the first name in the list who has one 'J', but then if i press 'O' in place to add if after the 'J' is looking for names beginning by 'O'...

This problem is because of the line of the 'delete'? Before to read your last message i was 'fighting' with the combo but i didn't manage to resolve it...:-(
And as i have this error i am wondering if really it is because of this or not...

regards,
fko

Re: Autocomplete Combobox

Posted: Wed May 28, 2014 8:13 pm
by dunbarx
Hi.

I know that Klaus has been with you through most of this.

The "label" is a property of a control. You cannot operate directly on a property as you tried to:

Code: Select all

delete char -1 of( the label of button "TestCombo")
You can only "set" and "get" their values. And by "get" I mean "access", as in "put the label of btn 1 into fld 1". That sort of thing.

So you cannot "delete" a chunk of a property value. You have to place that value into a variable or other container, act on it there, and then reset the property with the new value.

get the tProperty of tObject
delete the last char of it
set the tProperty of tObject to it

Craig Newman

Re: Autocomplete Combobox

Posted: Wed May 28, 2014 8:49 pm
by fko
Hi Craig,

Thanks to clarify me this...:-)

After this nice explanation now it seems evident that it is not logical what i was writing, as i was trying to change the property of this object...

Now i have no more this error...:-)

But i still have the problem with the autocomplete as i explained in my last message...
So, it seems that was not because of this error that i can't add more than one letter...:-(

regards,
fko

Re: Autocomplete Combobox

Posted: Thu May 29, 2014 4:25 am
by jacque
I don't think a combobox is the right thing to use here. Any matched word you put into the label will replace the user's typed content (Klaus mentioned that.) If the match isn't correct, the user must delete the extra characters so they can type the correct ones. For example, they type "J" and your match sets the label to "John". They don't want John, they want "Josh", so they delete 2 characters and type "s" for "Jos". Your match sets the label to "Joseph". They don't want that, so they delete three characters. Then they type "h" to make "Josh". It's a match.

Your user had to work very hard for those four characters. They won't like it.

One way to make suggestions is to use a text field for typing and a list field containing the list of suggestions. (Also, this way you don't need to store the list in a variable. Just put the database values directly into the list field.) Place the list field below the typing field and when you find a match, show the list field, set the hilitedLine to the matched line, and set its scroll so that the match moves to the top. The user can click the field to enter the match, or continue typing if they don't want the suggestion. This is similar to the way browsers like Firefox make suggestions when you type a URL. A list of URL matches appears under the navigation bar and you can click the one you want to use, or just keep typing if you want something different.

Re: Autocomplete Combobox

Posted: Thu May 29, 2014 8:27 am
by fko
Hi Jacque,

Thanks for your council...

Yes, maybe it will hard to the user as i was trying to do...:-(

I will try as you explained me...

regards,
fko