Combo box: text selection
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Combo box: text selection
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).
Thank you.
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).
Thank you.
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Combo box: text selection
Zax.
The only thing I can think of is:
What do you want to do this for?
Craig
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
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Combo box: text selection
Zax.
Doing this is digging into the IDE a bit, but that is not uncommon:
But again, kludges aside, is this the best way to do what you want/
Craig
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
Craig
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Combo box: text selection
Yes: the menuItem can be selected: but any change made by the end-user does NOT end up among the menuItems:
- -
That is because whatever the end-user enters is set as the LABEL of the combo thing:
-
-
- -
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
- Attachments
-
- Combo Nonsense.livecode.zip
- Stack.
- (940 Bytes) Downloaded 51 times
-
- VIP Livecode Opensource Backer
- Posts: 9670
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Combo box: text selection
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
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
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Combo box: text selection
Using a combo menu for end-user data entry makes almost no sense at all.
I generally use fields.
I generally use fields.
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Combo box: text selection
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.richmond62 wrote: ↑Wed May 10, 2023 9:02 pmUsing a combo menu for end-user data entry makes almost no sense at all.
I generally use fields.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Combo box: text selection
Thanks for all your answers.
FourthWorld is right:
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:
So, I'll use:
as you said.
Thanks again
FourthWorld is right:
Combo box can be a shortcut to a field + a popup menu.FourthWorld wrote: ↑Thu May 11, 2023 12:03 amCombo 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
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:
So, I'll use:
Code: Select all
click at the loc of btn "yourCombo"
Thanks again
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Combo box: text selection
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:
-
instead of vanishing when it is clicked:
Code: Select all
on mouseUp
ask "Value "
put it into item 1 of btn "cmenu"
end mouseUp
- Attachments
-
- Combo Stuff.livecode.zip
- Stack.
- (1.01 KiB) Downloaded 58 times
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Combo box: text selection
Of course, you can have this sort of code in your combo button:
Code: Select all
on menuPick XXX
put XXX
end menuPick
-
- VIP Livecode Opensource Backer
- Posts: 327
- Joined: Sun Apr 15, 2012 1:17 am
- Location: USA
- Contact:
Re: Combo box: text selection
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
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/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: Combo box: text selection
Thank you Cyril.
Maybe it's the simplest and safest way to do what I want.
Maybe it's the simplest and safest way to do what I want.
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Combo box: text selection
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Livecode Opensource Backer
- Posts: 9389
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Combo box: text selection
Um? Got me there: pray expand and explain.prefab listings
-
- VIP Livecode Opensource Backer
- Posts: 9842
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Combo box: text selection
Displayed menu items predefined by the software author.richmond62 wrote: ↑Thu May 11, 2023 8:25 pmUm? Got me there: pray expand and explain.prefab listings
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