Option Menu
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Option Menu
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?
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Option Menu
See the tag option for the menu entry in the Dictionary:
[<flags>] <label> ['/' <accelerator> ['|' <tag>]]
[<flags>] <label> ['/' <accelerator> ['|' <tag>]]
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Option Menu
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
i want it to work more like this.
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
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
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Option Menu
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:
Then in the option control use this script:
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.
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
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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Option Menu
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
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.
Re: Option Menu
Sure, as long as your user knows WHICH of the X identical names to select from the menu!Da_Elf wrote:this looks good so far but would lineoffset be able to work if there are 3 people with the same name?

Re: Option Menu
Klaus wrote:Sure, as long as your user knows WHICH of the X identical names to select from the menu!
if there are 3 bobs
bob
bob
bob
and i select the 3rd bob. lineoffset will only look towards the 1st bob
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Option Menu
No, but your question prompted me to realize that my code is working far harder than it needs to.Da_Elf wrote:this looks good so far but would lineoffset be able to work if there are 3 people with the same name?
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Option Menu
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
menupick sends its own line number? how. pItem is the text not a line number
Re: Option Menu
Hi Da_Elf
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:
You get the picture
Best
Klaus
True, but Bob #1 IS in fact the correct Bob!Da_Elf wrote:if there are 3 bobsKlaus wrote:Sure, as long as your user knows WHICH of the X identical names to select from the menu!
bob
bob
bob
and i select the 3rd bob. lineoffset will only look towards the 1st bob

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

Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Option Menu
You're right. I need coffee (too much time in mobile, where picklists always return only the item number).Da_Elf wrote:menupick sends its own line number? how. pItem is the text not a line 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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Option Menu
i will try that as soon as i get home
Re: Option Menu
menuhistory worked like a charm
Re: Option Menu
Not surprised! 
