Page 1 of 2

Combo box: text selection

Posted: Wed May 10, 2023 1:19 pm
by Zax
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 8145 times

Thank you.

Re: Combo box: text selection

Posted: Wed May 10, 2023 6:52 pm
by dunbarx
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

Re: Combo box: text selection

Posted: Wed May 10, 2023 6:57 pm
by dunbarx
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

Re: Combo box: text selection

Posted: Wed May 10, 2023 7:21 pm
by richmond62
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 8117 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
-

Re: Combo box: text selection

Posted: Wed May 10, 2023 8:42 pm
by dunbarx
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

Re: Combo box: text selection

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

I generally use fields.

Re: Combo box: text selection

Posted: Thu May 11, 2023 12:03 am
by FourthWorld
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

Re: Combo box: text selection

Posted: Thu May 11, 2023 8:01 am
by Zax
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 8042 times

So, I'll use:

Code: Select all

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

Thanks again :)

Re: Combo box: text selection

Posted: Thu May 11, 2023 8:18 am
by richmond62
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

Re: Combo box: text selection

Posted: Thu May 11, 2023 9:24 am
by richmond62
Of course, you can have this sort of code in your combo button:

Code: Select all

on menuPick XXX
   put XXX
end menuPick

Re: Combo box: text selection

Posted: Thu May 11, 2023 5:02 pm
by Newbie4
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

Re: Combo box: text selection

Posted: Thu May 11, 2023 6:27 pm
by Zax
Thank you Cyril.
Maybe it's the simplest and safest way to do what I want.

Re: Combo box: text selection

Posted: Thu May 11, 2023 8:14 pm
by FourthWorld
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).

Re: Combo box: text selection

Posted: Thu May 11, 2023 8:25 pm
by richmond62
prefab listings
Um? Got me there: pray expand and explain.

Re: Combo box: text selection

Posted: Thu May 11, 2023 9:29 pm
by FourthWorld
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.