Option Menu

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Quinton B.
Posts: 108
Joined: Mon Mar 20, 2017 5:13 am

Option Menu

Post by Quinton B. » Sat Jul 21, 2018 12:28 pm

I can correctly get the current year, but need to put the previous years (up to 100) in the format below:

2018
2017
2016
2015
and so on

this data will go into the menu items of the option menu.

I don't know how to put the dates in the format above.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Option Menu

Post by jmburnod » Sat Jul 21, 2018 1:15 pm

Hi,

This should work

Code: Select all

on mouseup
   put empty into t
   repeat with i = 2018 down to 1918
      put i & cr after t
   end repeat
   delete char -1 of t
   set the text of btn "myMenuOption" to t
end mouseup
Best regards
Jean-Marc
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Sat Jul 21, 2018 2:04 pm

That is an awfully long list. I would recommend that you not do this.

In the US, we are constantly presented with a dropDown of the 50 states when entering addresses for whatever onLine thing we are filling out. It is always a pain, even when one can type the first char of ones state to bring the list to that portion of the overall set.

100 is at least twice as onerous.

A much better way is to allow the user to start typing into a field, and a dropDown appears after, say, the second or third character, filtering out all but those items that match. Now a very short list appears, and the process is actually fun to use.

Need advice?

Craig newman

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Option Menu

Post by bogs » Sat Jul 21, 2018 3:07 pm

What Craig said, bonus it is the basis for a good autocomplete routine as well. Nice.
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Option Menu

Post by Klaus » Sat Jul 21, 2018 3:13 pm

I think in case of numbers we could trust our users to enter the number into a field, right?

Or provide a field with the number and one of these tiny scrollbars to de-/increase the
initial number in the field.

rjd
Posts: 16
Joined: Thu Aug 29, 2013 11:29 am

Re: Option Menu

Post by rjd » Mon Jul 23, 2018 5:10 pm

Hi Craig -- do you have an example stack of a dropDown field that does what you are describing below? The filtering of the items in a large list to limit choices after a few characters are typed sounds like something useful in many similar cases (like a search).
dunbarx wrote:
Sat Jul 21, 2018 2:04 pm
That is an awfully long list. I would recommend that you not do this.

In the US, we are constantly presented with a dropDown of the 50 states when entering addresses for whatever onLine thing we are filling out. It is always a pain, even when one can type the first char of ones state to bring the list to that portion of the overall set.

100 is at least twice as onerous.

A much better way is to allow the user to start typing into a field, and a dropDown appears after, say, the second or third character, filtering out all but those items that match. Now a very short list appears, and the process is actually fun to use.

Need advice?

Craig newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Mon Jul 23, 2018 7:58 pm

Hi.

On a new card, make two locked fields. Name one "entryField" and the other "selector". Make the height of fld "selector several lines high. Put a long list of any kind into a custom property of fld "entryField" named "contents'". I include a list of the states below if you want to start testing right away. But I would create your own list with many rather similar lines, so that you can see the list adjust as you continue typing and/or deleting chars.

In the script of fld "selector":

Code: Select all

on mouseUp
   answer the value of the selectedLine
end mouseUp
In the script of fld "entryField":

Code: Select all

local tList

on mouseEnter
   hide fld "selector"
   put "" into me
   put the contents of me into tList
   sort tList
end mouseEnter

on rawKeydown tKey
   switch 
      case tKey = 65288
         delete the last char of me
         if the length of me < 3 then hide fld "selector"
         break
      case toUpper(tKey) > 96 and  toUpper(tKey) < 122 or tKey = 32
         put numToChar(tKey) after me
         if the length of me > 2 and lineOffset(me,tList) <> 0 then
            show fld "selector"
            put line lineOffset(me,tList) to lineOffset(me,tList) + 5 of tList into fld "selector"
         end if
         break
   end switch
end rawKeydown
You may well want to change the UI here. But for this example, if you click on fld "entryField" and start typing, at the third char any foundLine will appear in fld "selector", along with its following few neighbors.If you backspace, the list will adjust. As you type more and more chars, the field will adjust. You may want to include preceding lines as well, whatever.

Write back with comments and complaints.

Craig

Here are the states.
Alabama
Alaska
Arizona
Arkansas
California
Colorado
Connecticut
Delaware
Florida
Georgia
Hawaii
Idaho
Illinois
Indiana
Iowa
Kansas
Kentucky
Louisiana
Maine
Maryland
Massachusetts
Michigan
Minnesota
Mississippi
Missouri
Montana
Nebraska
Nevada
New Hampshire
New Jersey
New Mexico
New York
North Carolina
North Dakota
Ohio
Oklahoma
Oregon
Pennsylvania
Rhode Island
South Carolina
South Dakota
Tennessee
Texas
Utah
Vermont
Virginia
Washington
West Virginia
Wisconsin
Wyoming

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Mon Jul 23, 2018 11:56 pm

When you get a chance, perhaps after trying the above gadget, can you winnow out a single result, so that it is not just the line at the top of the list that likely is the line you want, but that when the chars in the entry field have finally defined a single unique "hit", all the others go away?

I am here waiting.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Option Menu

Post by jacque » Tue Jul 24, 2018 8:55 pm

I use variations of the following, which uses a search field for the user to type into, and a results list field that shows matches for whatever the user types. The complete, original list of choices is stored in a cList cutom property of the search field. The handler goes into the search field:

Code: Select all

on textChanged
  put the cList of me into tFullList
  if me <> empty then
    filter tFullList with ("*" & me & "*")
  end if
  put tFullList & cr into fld "searchResults"
  show fld "searchResults"
end textChanged
Unless you want the results to always show, this assumes that when the user makes a selection, the searchResults field will hide itself. It also needs to hide if the user clicks outside the field.

The filter will find any match wherever it is in the list lines. If you only want to find matches at the beginning of lines change the filter to:

Code: Select all

filter it with (me & "*")

Edit: I see I've answered a question you didn't ask. Well, maybe this will be useful to someone, sometime, so I'll leave it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Option Menu

Post by dunbarx » Tue Jul 24, 2018 9:28 pm

Jacque.

"Filter" is a bit more modern and likely a bit faster, I think, and just as effective. For me, I do not think, especially in a long list, that anything at all should appear until at least the third char.

Sorting the results is critical when one is zeroing in on the target string, whether done before or after the winnowing.

Craig

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”