Page 1 of 1

PullDown-menu select item with typing in the name

Posted: Sun Sep 13, 2015 10:20 am
by User87
Hello,
I have a pull-down menu with some item (e.g. red, green, blue, yellow) now I do not want to select the items by clicking with the mouse on it.
I want to select the item by typing in the name "blue" with my keyboard and then the item "blue" should be marked and then I want to press enter to select this item.

Can anybody help me?

Re: PullDown-menu select item with typing in the name

Posted: Sun Sep 13, 2015 3:46 pm
by dunbarx
Hi.

So much fun.

On a new card make two buttons and a field. One of the buttons will be a pullDown, named "pd", and why not load those colors into it. In the other button:

Code: Select all

global tPullDown

on mouseUp
   put "" into tPullDown
   put "" into fld 1
end mouseUp
Now in the card script:

Code: Select all

global tPullDown

on keydown tKey
   set the wholematches to "true"
   put tKey after tPullDown
   get btn "pd"
   put  tPullDown && lineOffset(tPullDown,it) into fld 1
   if word 1 of fld 1 is among the lines of it then
      set the label of btn "pd" to  word 1 of fld 1
      put "" into tPullDown
      put "" into fld 1
   end if
end keydown
This is a very wordy lesson. The field and the normal button are gratuitous, just to let you see how things develop. Write back with any complaints.

Craig Newman

EDIT: Maybe this should come with instructions. You must not have that field in focus or strange things might happen. Remember you do not need it at all. I took you at your word when you said you just wanted to type on the keyboard, and that meant to me that no fields were involved. There are likely many things that need to be adapted to this handler, but it should get the idea across. For example, if you have a bunch of colors in the pulldown, but type something that never matches any of the menuItems, you can see that the field collects all that typing, and never stops. So how do you cover that issue? Hmmm. Maybe check out the "length" function?

Re: PullDown-menu select item with typing in the name

Posted: Mon Sep 14, 2015 11:45 am
by User87
Thanks for that. I experiment with that.

Can you tell me if it's possible to enter the pull-down with the tab key on my keyboard?
If I use the tab key it change between the push-button and the field. But the pull-down is ignored.

For instance some of the menu item are: lime, light-grey, light-blue, light-red:
1. I want to use the tab key to navigate to the pull-down.
2. I want to type in with my keyboard for instance "li" and want the pull-down menu to pull-down to see all the items in it and mark the first item that begins with "li" with a blue background. But I do not yet want the menu item to be choosen.
3. I want to navigate with the key arrow (up and down arrow) to the menu item I want to have (and everytime I navigate with the arrow keys the menu item becomes a blue background). So I navigate with the arrow-key to the menu item light-blue. Now light-blue becomes a blue background and now I want to press the enter key. First at this moment (by pressing the enter key) I want the menu item to be selected.

Cann you help me please?

Re: PullDown-menu select item with typing in the name

Posted: Mon Sep 14, 2015 6:58 pm
by dunbarx
Well, for item 1 right now, try this. Make a new card with three fields. Name the fields "F1", "F2" and "F3". Now bring over your pulldown. In the card script:

Code: Select all

on tabKey
   if the short name of the focusedobject = "F3" then
      click at the loc of btn 1
   end if
   pass tabKey
end tabKey
Set the cursor in field "F1". Press the tab ket a couple of times. Again, it is likely that you will need to add both your own functionality and also some stuff that will avert danger.

Craig

Re: PullDown-menu select item with typing in the name

Posted: Mon Sep 14, 2015 8:07 pm
by dunbarx
Reading the other two wish-list items you mentioned, I wonder if there is a better way to do this than with a pulldown. As you might have figured out, my solution for the first item is a kluge. I like kluges, but not when they start to take over.

So this is a clue that it is time to rethink the problem. Instead of a pulldown, why not use a list field? Looks aside, it is MUCH easier to do all the little things you are asking for in that object, especially some sort of narrowing binary search based on user input. And as for that "looks" thing I mentioned, you now have all the power of LC to make this field appear the way you want it to. Frankly, you are asking too much of a pulldown, which should really be a simple object to select a small number of fixed menuItems.

The real question is this: how far along are you with learning LiveCode? Please do write back with the answer. It matters...

Craig

Re: PullDown-menu select item with typing in the name

Posted: Mon Sep 14, 2015 9:27 pm
by User87
Hello Craig,
thanks for so much efforts.
Okay if it is better to use a list field I will try to use one, even if I then have to reprogram my previous program.

To your question how far I am with learning LiveCode:
I am a total beginner, I use LiveCode for a few weeks.

Also I do not understand your solution with the 3 field "F1, F2, F3" in the new card. Do these fields stay in the new card, and why are there 3 fields?
I tried to use (click at the loc of btn "pd") before and put it into the field 1. But the problem is that if I want to tab away from the pull down it's not possible and navigates through the menu items instead of jump to the next button or field.

Re: PullDown-menu select item with typing in the name

Posted: Tue Sep 15, 2015 5:23 am
by dunbarx
Hi.

The three field gadgeet was just to allow you to see that you can tab into a pulldown, and invoke its action. LiveCode is very flexible and powerful that way. But this is a kluge; I clicked at the loc of that pulldown under script control to simulate the user clicking with the mouse.

As I said, these are all just clues to solve specific issues you encounter on the way to authoring your own application. The examples given are all lessons to study. They are probably not a basis for your project.

The helpers here are all volunteers. We will not write your project, but we will help you as long as you can stand our feedback. You are a beginner. Your job is to learn and practice. Step through the handlers to see how they work. It will take a few months of steady effort before everythiing starts to really make sense, and you gain confidence in your own ability. You must plan and create your stack, and you must have a solid foundation with the basics of LC in order to do that. In the meantime feel free to ask for help with anything at all.

Here is another exercise. Create a field with many colors, one per line. Create another field where the user can enter text. And finally create a third field that will contain all the colors that match whatever text is being typed. Can you see how to do that?

Craig