Page 1 of 1

Option Menu

Posted: Tue May 10, 2016 1:38 pm
by Da_Elf
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?

Re: Option Menu

Posted: Tue May 10, 2016 2:12 pm
by FourthWorld
See the tag option for the menu entry in the Dictionary:
[<flags>] <label> ['/' <accelerator> ['|' <tag>]]

Re: Option Menu

Posted: Tue May 10, 2016 5:23 pm
by Da_Elf
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

Re: Option Menu

Posted: Tue May 10, 2016 5:58 pm
by FourthWorld
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.

Re: Option Menu

Posted: Tue May 10, 2016 7:28 pm
by Da_Elf
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

Re: Option Menu

Posted: Tue May 10, 2016 7:41 pm
by Klaus
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)

Re: Option Menu

Posted: Tue May 10, 2016 7:44 pm
by Da_Elf
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

Re: Option Menu

Posted: Tue May 10, 2016 7:48 pm
by FourthWorld
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?

Re: Option Menu

Posted: Tue May 10, 2016 7:54 pm
by Da_Elf
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

Re: Option Menu

Posted: Tue May 10, 2016 8:11 pm
by Klaus
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

Re: Option Menu

Posted: Tue May 10, 2016 8:15 pm
by FourthWorld
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.

Re: Option Menu

Posted: Tue May 10, 2016 10:44 pm
by Da_Elf
i will try that as soon as i get home

Re: Option Menu

Posted: Wed May 11, 2016 12:10 pm
by Da_Elf
menuhistory worked like a charm

Re: Option Menu

Posted: Wed May 11, 2016 12:18 pm
by Klaus
Not surprised! :D