Combo box: text selection

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

Zax
Posts: 475
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Combo box: text selection

Post by Zax » Wed May 10, 2023 1:19 pm

Hello,

How can I select/hilite the text entered by a user in a combo box?
I have to check the entered value is a number and, if not, display an alert. In this case, in order to have a friendly UI, I would like to select the entered text.

I understand a combo box is a mix between button and field, but I can't use "select line 1 of ..." because it will trigger a menuPick event.
In the same way, "select text of..." has no effect.
Also, LC doesn't understand "select the label of...".

The first line of a combo box can be manually selected (see screen capture).
ScreenCapture 2023-05-10 à 14.08.27.jpg
ScreenCapture 2023-05-10 à 14.08.27.jpg (12.1 KiB) Viewed 4973 times

Thank you.

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

Re: Combo box: text selection

Post by dunbarx » Wed May 10, 2023 6:52 pm

Zax.
The only thing I can think of is:

Code: Select all

on mouseUp
   click at the loc of btn "yourCombo"
   answer the text of the selectedField
end mouseUp
What do you want to do this for?

Craig

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

Re: Combo box: text selection

Post by dunbarx » Wed May 10, 2023 6:57 pm

Zax.

Doing this is digging into the IDE a bit, but that is not uncommon:

Code: Select all

on mouseUp
   click at the loc of btn "yourCombo"
   if the text of the selectedField is a number then answer "OK"
   else answer "AAARRGHH"
end mouseUp
But again, kludges aside, is this the best way to do what you want/

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Combo box: text selection

Post by richmond62 » Wed May 10, 2023 7:21 pm

Yes: the menuItem can be selected: but any change made by the end-user does NOT end up among the menuItems:
-
SShot 2023-05-10 at 21.15.03.png
SShot 2023-05-10 at 21.15.03.png (10.37 KiB) Viewed 4945 times
-
That is because whatever the end-user enters is set as the LABEL of the combo thing:

Code: Select all

on mouseUp
   put the label of btn "cMenu" into checkIT
   if checkIT is a number then answer "it's a number"
   else answer "Nope"
end mouseUp
-
SShot 2023-05-10 at 21.20.07.png
-
Attachments
Combo Nonsense.livecode.zip
Stack.
(940 Bytes) Downloaded 51 times

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

Re: Combo box: text selection

Post by dunbarx » Wed May 10, 2023 8:42 pm

Richmond is correct in saying that the label of a combo box is what is displayed in that gadget. This however you get there, either by manual entry or menuItem selection.

But now I wonder why you are using one at all.You mentioned that the user was going to enter data into the combo field, and not, as is usual, select a menuItem from the combo itself. Why use a combo box then? Or can one do both?

But if not, then the kludgey stuff above will all work, but it is kludgey.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Combo box: text selection

Post by richmond62 » Wed May 10, 2023 9:02 pm

Using a combo menu for end-user data entry makes almost no sense at all.

I generally use fields.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Combo box: text selection

Post by FourthWorld » Thu May 11, 2023 12:03 am

richmond62 wrote:
Wed May 10, 2023 9:02 pm
Using a combo menu for end-user data entry makes almost no sense at all.

I generally use fields.
Combo boxes are a good fit where most of the time you'll want to offer a selection of predefined values, but also need to accommodate the option of allowing a unique entry.

Microsoft Windows popularized this control type, initially absent from early Mac versions. But eventually Mac OS (what we now call "Classic") caught up, and macOS (OS X) still supports them:
https://developer.apple.com/design/huma ... ombo-boxes
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Zax
Posts: 475
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Combo box: text selection

Post by Zax » Thu May 11, 2023 8:01 am

Thanks for all your answers.

FourthWorld is right:
FourthWorld wrote:
Thu May 11, 2023 12:03 am
Combo boxes are a good fit where most of the time you'll want to offer a selection of predefined values, but also need to accommodate the option of allowing a unique entry.

Microsoft Windows popularized this control type, initially absent from early Mac versions. But eventually Mac OS (what we now call "Classic") caught up, and macOS (OS X) still supports them:
https://developer.apple.com/design/huma ... ombo-boxes
Combo box can be a shortcut to a field + a popup menu.
When a user has to fill a form, and when an entered value is not valid, I think it is cool to select the bad field so the user knows exactly where is the problem.
In my case, it's about aspect ratio for images:
ScreenCapture 2023-05-11 à 09.06.22.jpg
ScreenCapture 2023-05-11 à 09.06.22.jpg (17.31 KiB) Viewed 4870 times

So, I'll use:

Code: Select all

click at the loc of btn "yourCombo"
as you said.

Thanks again :)

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Combo box: text selection

Post by richmond62 » Thu May 11, 2023 8:18 am

You can allow end-users to enter values in this way, which means they remain in the drop down menu
instead of vanishing when it is clicked:

Code: Select all

on mouseUp
   ask "Value "
   put it into item 1 of btn "cmenu"
end mouseUp
-
Screen Shot 2023-05-11 at 10.16.59 am.png
Attachments
Combo Stuff.livecode.zip
Stack.
(1.01 KiB) Downloaded 58 times

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Combo box: text selection

Post by richmond62 » Thu May 11, 2023 9:24 am

Of course, you can have this sort of code in your combo button:

Code: Select all

on menuPick XXX
   put XXX
end menuPick

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: Combo box: text selection

Post by Newbie4 » Thu May 11, 2023 5:02 pm

Another way to allow the user to add choices to the list:

add an item "new" to your list of choices and when the user chooses "new" it will ask for a new value and add it to the future list of choices

Code: Select all

on menuPick pItem
   switch pItem
      case "new" 
         ask "new list item:"
         put it into pNewItem
         put cr & pNewItem after button "cbm"
         put pNewItem into x
   end switch
   // rest of code to do what you wish with the user's choice
end menuPick
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

Zax
Posts: 475
Joined: Mon May 28, 2007 10:12 am
Location: France
Contact:

Re: Combo box: text selection

Post by Zax » Thu May 11, 2023 6:27 pm

Thank you Cyril.
Maybe it's the simplest and safest way to do what I want.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Combo box: text selection

Post by FourthWorld » Thu May 11, 2023 8:14 pm

Zax wrote:
Thu May 11, 2023 6:27 pm
Thank you Cyril.
Maybe it's the simplest and safest way to do what I want.
If you want user additions to be added to the menu, Cyril's option supports Apple's guidance on combo boxes being best for those cases where open-ended entry is needed but which does not affect the prefab listings (tho FWIW MS has different guidance on that).
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9389
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Combo box: text selection

Post by richmond62 » Thu May 11, 2023 8:25 pm

prefab listings
Um? Got me there: pray expand and explain.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Combo box: text selection

Post by FourthWorld » Thu May 11, 2023 9:29 pm

richmond62 wrote:
Thu May 11, 2023 8:25 pm
prefab listings
Um? Got me there: pray expand and explain.
Displayed menu items predefined by the software author.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”