Function Repository Resource:

PopupMenuOther

Source Notebook

A version of PopupMenu that provides an InputField to enter "other" values

Contributed by: Jon McLoone

ResourceFunction["PopupMenuOther"][Dynamic[var],{val1,val2,}]

creates a PopupMenu with an extra "Other…" item which displays an InputField for the user to fill.

ResourceFunction["PopupMenuOther"][Dynamic[var],{val1,val2,},label]

uses label as the label for the extra item.

ResourceFunction["PopupMenuOther"][Dynamic[var],{val1,val2,},labelcontents]

accepts input of type contents.

Details

ResourceFunction["PopupMenuOther"] accepts all options for PopupMenu and InputField
Accepted contents values are the same as InputField types and include Number, Expression and String.

Examples

Basic Examples (3) 

A popup menu for a user to indicate how they heard about a service:

In[1]:=
ResourceFunction["PopupMenuOther"][
 Dynamic[where1], {"Advert", "Email", "Word of mouth"}]
Out[1]=

If the user selects “Other…” an InputField appears for them to provide more detail:

In[2]:=
ResourceFunction["PopupMenuOther"][
 Dynamic[where2], {"Advert", "Email", "Word of mouth"}]
Out[2]=

You can change the label for the "other" item:

In[3]:=
ResourceFunction["PopupMenuOther"][
 Dynamic[where2], {"Advert", "Email", "Word of mouth"}, "Somewhere else\[Ellipsis]"]
Out[3]=

By default the InputField interpret the contents as a String but other types available to InputField can be used:

In[4]:=
ResourceFunction["PopupMenuOther"][
 Dynamic[howmany], {1 -> "One", 2 -> "two"}, "Other quantity" -> Number]
Out[4]=

Options (2) 

All standard options for PopupMenu and InputField are supported. For example, use FieldHint to prompt the user:

In[5]:=
ResourceFunction["PopupMenuOther"][
 Dynamic[where3], {"Advert", "Email", "Word of mouth"}, "Other\[Ellipsis]", FieldHint -> "Please provide details"]
Out[5]=

If the option is valid for both PopupMenu and InputField, its value will be used by both:

In[6]:=
ResourceFunction["PopupMenuOther"][
 Dynamic[where3], {"Advert", "Email", "Word of mouth"}, "Other\[Ellipsis]", ImageSize -> {500, 30}]
Out[6]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 01 March 2022

Related Resources

License Information