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
Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Option Menu

Post by Da_Elf » Tue May 10, 2016 1:38 pm

in HTML there is a different between the value of an option and the visible text of an option. Is there any way of doing this in livecode?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Option Menu

Post by FourthWorld » Tue May 10, 2016 2:12 pm

See the tag option for the menu entry in the Dictionary:
[<flags>] <label> ['/' <accelerator> ['|' <tag>]]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Option Menu

Post by Da_Elf » Tue May 10, 2016 5:23 pm

im sorry to say it but that entry in the dictionary makes no sense what so ever.
if in html i have this

<select name="myselect">
<option value='00001'>Cars</option>
<option value='00002'>Busses</option>
</select>

How would i setup an option menu so that if i click on cars i get the value 00001.

Im populating the option menu from a database. i want to SEE the persons name. but when i select it i get their ID instead

normally im stuck doing this

Code: Select all

put "SELECT name FROM students WHERE form='"&formName&"' ORDER BY name" into thename
   dbaseConnect
   put revDataFromQuery(tab, cr, gConnectionID, thename) into trName
   dbaseDisconnect
   set itemDelimiter to cr
   set the text of btn "opStudent" to trName
   set the label of btn "opStudent" to item 1 of trName
i want it to work more like this.

Code: Select all

   put "SELECT id,name FROM students WHERE form='"&formName&"' ORDER BY name" into thename
   dbaseConnect
   put revDataFromQuery(tab, cr, gConnectionID, thename) into trName
   dbaseDisconnect
   set itemDelimiter to cr
   put empty into myList
   repeat for each item li in trName
      set itemDelimiter to tab
      put item 2 of li & cr after myList
      --Somewhere here i want to set item 1 of li as the real value of the list of names
      set itemDelimiter to cr
   end repeat
   delete the last char of myList
   set the text of btn "opStudent" to myList

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Option Menu

Post by FourthWorld » Tue May 10, 2016 5:58 pm

My bad: I had thought menu tags work with all menu styles, but apparently with pulldowns but not option controls - I just submitted a request for that:
http://quality.livecode.com/show_bug.cgi?id=17611

As a workaround in the meantime you can do this with a custom property - put this in a custom prop named uTagItems:

Code: Select all

Cars|00001
Busses|00002
Then in the option control use this script:

Code: Select all

on mouseDown
   put the uTagItems of me into tList
   set the itemdel to "|"
   repeat for each line tLine in tList 
      put item 1 of tLine &cr after tItems
   end repeat
   delete last char of tItems
   set the text of me to tITems
end mouseDown

on menuPick pItem
   put the uTagItems of me into tList
   put lineoffset(cr& pItem &"|", cr& tList) into tLineNum
   set the itemdel to "|"
   put item 2 of line tLineNum of tList into tVal
   DoSomethingWith tVal
end menuPick
Not quite as elegant as the built-in menu tags for pulldown menus, but at least it'll get you going with your option control for now.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Option Menu

Post by Da_Elf » Tue May 10, 2016 7:28 pm

this looks good so far but would lineoffset be able to work if there are 3 people with the same name?

just tested. it doesnt work. I have 2 names the same and it keeps going for the first one. i know i probably wont have 2 names the same but i just wanted to cover my ass
Last edited by Da_Elf on Tue May 10, 2016 7:41 pm, edited 1 time in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Option Menu

Post by Klaus » Tue May 10, 2016 7:41 pm

Da_Elf wrote:this looks good so far but would lineoffset be able to work if there are 3 people with the same name?
Sure, as long as your user knows WHICH of the X identical names to select from the menu! 8)

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Option Menu

Post by Da_Elf » Tue May 10, 2016 7:44 pm

Klaus wrote:Sure, as long as your user knows WHICH of the X identical names to select from the menu! 8)

if there are 3 bobs
bob
bob
bob
and i select the 3rd bob. lineoffset will only look towards the 1st bob

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Option Menu

Post by FourthWorld » Tue May 10, 2016 7:48 pm

Da_Elf wrote:this looks good so far but would lineoffset be able to work if there are 3 people with the same name?
No, but your question prompted me to realize that my code is working far harder than it needs to.

Because the items are displayed in the order they appear in the custom prop, and because the arg sent to menuPick handler is the item number selected, you don't really need lineoffset at all, just use the argument provided.

This does raise a UX issue, though: how will the user know which "Bob" they're selecting?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Option Menu

Post by Da_Elf » Tue May 10, 2016 7:54 pm

im not too worried about multiple bobs i will have blocks for that on the input level. but im doing this to cover my ass just incase

menupick sends its own line number? how. pItem is the text not a line number

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Option Menu

Post by Klaus » Tue May 10, 2016 8:11 pm

Hi Da_Elf
Da_Elf wrote:
Klaus wrote:Sure, as long as your user knows WHICH of the X identical names to select from the menu! 8)
if there are 3 bobs
bob
bob
bob
and i select the 3rd bob. lineoffset will only look towards the 1st bob
True, but Bob #1 IS in fact the correct Bob! :D

Just kidding, but you can use "the menuhistory" together with the custom props proposed by Richard!
And you don't even need a PAIR of correponding name/ids!

Custom property content:
001
002
003
004

Menu content:
Jones
Barker
Miller
Smith

Script:

Code: Select all

on menupick tWhich
  put the menuhistory of me into tLine
  answer line tLine of the cPropWithIDs of me
end menupick
You get the picture :D


Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Option Menu

Post by FourthWorld » Tue May 10, 2016 8:15 pm

Da_Elf wrote:menupick sends its own line number? how. pItem is the text not a line number
You're right. I need coffee (too much time in mobile, where picklists always return only the item number). :)

Klaus has you covered: what I was thinking of was the menuHistory property.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Option Menu

Post by Da_Elf » Tue May 10, 2016 10:44 pm

i will try that as soon as i get home

Da_Elf
Posts: 311
Joined: Sun Apr 27, 2014 2:45 am

Re: Option Menu

Post by Da_Elf » Wed May 11, 2016 12:10 pm

menuhistory worked like a charm

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Option Menu

Post by Klaus » Wed May 11, 2016 12:18 pm

Not surprised! :D

Post Reply