SOLVED - Drop Downs / Combo Boxes not working properly

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Drop Downs / Combo Boxes not working properly

Post by Regulae » Thu Jul 14, 2011 4:08 pm

Hi Mike,

I've prepared an improved (I hope) version, tackling some of the points you mentioned earlier. The "combo arrows" are now images which look more appropriate, and the scripts have been reworked to make it easier to reuse the group by a simple copy and paste. I've tried to include some explanation and comments in the scripts. It still is, it must be admitted, a work-around. I see that nothing misses Klaus's eagle eye, which is both reassuring and much appreciated.

Regards,

Michael
Attachments
ComboBox for revLet2.zip
(6.86 KiB) Downloaded 389 times

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

Re: Drop Downs / Combo Boxes not working properly

Post by Klaus » Thu Jul 14, 2011 4:21 pm

Regulae wrote:... I see that nothing misses Klaus's eagle eye, which is both reassuring and much appreciated.
LOL :D

Yes, I am in the "eagle eye" business for almost 50 years!
Here is the proof:
Image
Yep, that's me ca. 1962 8)


Best

Klaus

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: Drop Downs / Combo Boxes not working properly

Post by admin12 » Fri Jul 15, 2011 12:59 am

Regulae wrote:Hi Mike,

I've prepared an improved (I hope) version, tackling some of the points you mentioned earlier. The "combo arrows" are now images which look more appropriate, and the scripts have been reworked to make it easier to reuse the group by a simple copy and paste. I've tried to include some explanation and comments in the scripts. It still is, it must be admitted, a work-around. I see that nothing misses Klaus's eagle eye, which is both reassuring and much appreciated.

Regards,

Michael
Thank you. I will try it out and start using it in my projects. You guys are the best!

Mike

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Drop Downs / Combo Boxes not working properly

Post by Regulae » Fri Jul 15, 2011 3:45 am

Hi Mike,

Good to know things are progressing. I see now my version 2 is could be greatly improved- getting some sleep has helped. Something I'll look at, or others may have better ideas. Still, from the point of view of your project, given the client requirement that makes revlet deployment necessary, and the design requirement that, to give users a convenient way of choosing from potentially long lists, the combo box is appropriate, the key thing is to quickly establish a way of doing it. You are then free to concentrate on other priorities, and refinements can be made at leisure. You mentioned earlier some other problems, concerning TAB key functioning and error checking. Naturally, keep posting to the Forum when you get stuck. As a LiveCoder, you have an international team behind you.

@Klaus

A truly wonderful photograph! There is the face of a young man clearly destined for LiveCode greatness! The eagle-eye is unmistakable. Thanks for posting it- it brought a big smile to my face.

Regards,

Michael

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

Re: Drop Downs / Combo Boxes not working properly

Post by Klaus » Fri Jul 15, 2011 11:44 am

:D

SparkOut
Posts: 2943
Joined: Sun Sep 23, 2007 4:58 pm

Re: Drop Downs / Combo Boxes not working properly

Post by SparkOut » Fri Jul 15, 2011 2:06 pm

Hey Klausimausi - did you knock the wall down with your head? :lol:

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

Re: Drop Downs / Combo Boxes not working properly

Post by Klaus » Fri Jul 15, 2011 2:13 pm

You bet, but my hairdo did not suffer at all from that! :D

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: Drop Downs / Combo Boxes not working properly

Post by admin12 » Fri Jul 15, 2011 9:19 pm

Thanks Mike.

Yes, I want to be able to tab from one field to the next. The database uses standard forms in Live Code and the normal way of using a database is to tab through the fields, in order. How do I accomplish this in Live Code?

Mike

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Drop Downs / Combo Boxes not working properly

Post by Regulae » Sun Jul 17, 2011 2:16 pm

Hi Mike,

There's a little bit to the tab question that I needed to explore. Pressing the tab key jumps the cursor from one text field to another, in the order of their partNumbers on the card. The tab key visits fields with lower partNumbers before those with higher partNumbers. If you are developing a layout over time, adding, moving and deleting fields, the resultant fields can have partNumbers that don't follow the top/down left/right order one ultimately wants. From memory, I think this was what was happening in the example you posted- tab jumped the cursor between fields in an unintended manner. I've written two handlers which, if placed in the stack script, reorder left/right/top/down the fields on a card. Type "retab" in the message box. It will reorder the fields on the card you are currently on, (I believe) in the manner desired. The original order can be restored with "restoretab". The reordering can be repeated as often as required during the layout and development process:

Code: Select all

on Retab
   set the numberFormat to "000"
   repeat with i = 1 to the number of controls on this card
      put return&(the id of control i) before restorationList
      /* Only fields whose autoTab is true will be relayered. If you want all the fields on the card relayered,
      uncomment the next line, and comment out the more restrictive AND variant. */
      -- If word 1 of the name of control i = "field" then
      /* If, using the above line, you also to set the autoTab of all the fields to "true", uncomment this next small section: */
      --   If word 1 of the name of control i = "field" then
      --      set the autoTab of control i to true 
      --   end if
      if word 1 of the name of control i = "field" AND the autoTab of control i = "true" then
         put (the id of control i)&&(the partNumber of control i) into control i
         put (item 1 of the topLeft of control i) * 1 into topLeftX
         put (item 2 of the topLeft of control i) * 1 into topLeftY
         put (the id of control i)&","&topLeftY&","&topLeftX&return before controlList
      end if
   end repeat
   /* remove leading return in restorationList before saving in custom property "the restoreList of current card"
   The property is retrieved and used by the RestoreTab handler. */
   delete line 1 in restorationList
   set the restoreList of this card to restorationList
   /* controls sorted in ascending Y values (down the screen) */
   sort lines of controlList ascending by item 2 of each
   /* Consider two fields side by side, we would normally want tab to take us from the left field to the right. 
   After the first sort, if the field on the right is even one pixel higher than the one on the left, it will be considered "first". 
   This next sort adjustment corrects the problem, allowing a margin of error (+/-10 pixels) in field placement. */
   put controlList into newList
   put 0 into setY
   repeat with i = 2 to (the number of lines in controlList)
      if abs((item 2 of line i of controlList) - (item 2 of line (i - 1) of controlList)) < 10 then
         if setY = 0 then
            put (item 2 of line i of controlList) into item 2 of line (i - 1) of newList
            put (item 2 of line i of controlList) into setY
         end if
         if setY <> 0 then
            put setY into item 2 of line i of newList
         end if
      end if
      if abs((item 2 of line i of controlList) - (item 2 of line (i - 1) of controlList)) >= 10 then
         put 0 into setY
      end if
   end repeat
   sort lines of newList ascending by item 2 of each,item 3 of each
   set the lockScreen to true
   repeat for each line L in newList
      set the partNumber of control id (item 1 of L) to the number of parts
   end repeat
end Retab

on RestoreTab
   set the lockScreen to true
   put the restoreList of this card into restorationList
   repeat for each line L in restorationList
      if there is a control id L then
         set the partNumber of control id L to 1
      end if
   end repeat
   beep 1
end RestoreTab
You will see I've included some variants- by default I have it reordering all fields whose autoTab is true. If a field's autoTab is true, after the user has typed text in a field, pressing return or enter will jump them to the next field (whereas normally, pressing return in a field puts you on the next line in the same field). This may be desirable in the layout you showed. There is a small "commented out" section which facilitates setting the autoTab of all the fields if you want to do so. You have to do what is appropriate for your design- sometimes I use some fields to act as purely visual elements, like coloured boxes and so forth, and as they are not intended for data entry, you don't want tab to jump to them. It's worth knowing that if you want a specific field to be ignored by tab (and return/enter if the autoTab property is in general use) you can do this by setting its traversalOn to false.

The "Retab" handler determines the new order of fields based on their topLefts, ordered from top of screen down, with fields having roughly the same topLeft "y" value (thus in a line across the screen), ordered left to right. For the layout you showed, this should be appropriate, but as we are relying on the topLeft, there are some field arrangements where you might have to specify the partNumber/layer number with a particular field's property inspector to get the result you want. I've included the Restoretab handler to help retrieve a layout that "Retab" fails to handle well. I hope this goes some way to addressing your tab requirements- if not, naturally ask further.

I've made progress with a more generally usable revlet-friendly combo box, which I'll post shortly.

Regards,

Michael

admin12
Posts: 412
Joined: Wed May 11, 2011 9:47 am

Re: Drop Downs / Combo Boxes not working properly

Post by admin12 » Mon Jul 18, 2011 6:10 am

Michael,

Thank you so much. You are AWESOME! I will get to work on this and let you know how it goes.

Mike

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Drop Downs / Combo Boxes not working properly

Post by BarrySumpter » Tue Jul 19, 2011 1:07 am

Regulae wrote:Hi Mike,

I've had a shot at implementing a "roll your own" version of the combo box, which seems to work in revLets. It's fairly simple, but does the job. See the attached stack.

Regards,

Michael

Nice!
Thanks for posting that example.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: Drop Downs / Combo Boxes not working properly

Post by BarrySumpter » Tue Jul 19, 2011 1:21 am

Regulae wrote:Hi Mike,

I've prepared an improved (I hope) version, tackling some of the points you mentioned earlier. The "combo arrows" are now images which look more appropriate, and the scripts have been reworked to make it easier to reuse the group by a simple copy and paste. I've tried to include some explanation and comments in the scripts. It still is, it must be admitted, a work-around. I see that nothing misses Klaus's eagle eye, which is both reassuring and much appreciated.

Regards,

Michael
And another thanks you for posting v2.

I feel like I'm spending more time on work arounds than I should.

Thanks for saving me this time.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

Post Reply