Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by restdevelop · Nov 08, 2018 at 09:29 AM · inputfielddropdownsearch

Search in Dropdown options

Hi, I have a dropdown an there are a few options in it. I want click to inputfield and type something, inputfield shows me is there any words in dropdown. For example I typed ""am"" and finds me americo vespuci in dropdown. İs it possible?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Hellium · Nov 08, 2018 at 09:48 AM

 1. Create a new script called DropdownFilter.cs

 2. Copy-paste the following script

 public class DropdownFilter : MonoBehaviour
 {
     [SerializeField]
     private InputField inputField;
 
     [SerializeField]
     private Dropdown dropdown;
 
     private List<Dropdown.OptionData> dropdownOptions;
     
     private void Start()
     {
         dropdownOptions = dropdown.options;
     }    
     public void FilterDropdown( string input )
     {
         dropdown.options = dropdownOptions.FindAll( option => option.text.IndexOf( input ) >= 0 );
     }
 }

 3. Create the input field and dropdown UI elements

 4. Attach the script to the gameObject you want (an empty in your scene or the dropdown, or the input field, ...) you just have to make sure the gameObject is enabled when the scene starts

 5. Drag & drop the inputfield and dropdown in the appropriate fields in the inspector, when the gameObject holding the script is selected

 6. Add a new event in the OnValueChanged of the input field. Drag & drop the gameObject created step #5 (holding the DropdownFilter script) and select the FilterDropdown function (`DynamicString`)

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image restdevelop · Nov 08, 2018 at 10:56 AM 0
Share

Again you and again succes!

avatar image altropetrolio · May 20, 2020 at 06:04 AM 0
Share

Hello @Hellium . This script works well... however there are no control if "no items is found". There is a way to check to avoid this issue?

For example : FindAll cannot find string. I want to force Dropdown to stay at position 1. How to do this check and force position?

Thank you.

avatar image Hellium altropetrolio · May 20, 2020 at 06:24 AM 1
Share
  public void FilterDropdown( string input )
  {
      List<Dropdown.OptionData> filteredOptions = dropdownOptions.FindAll( option => option.text.IndexOf( input ) >= 0 );
      if(filteredOptions.Count > 0)
          dropdown.options = filteredOptions;
  }
avatar image dfarjoun Hellium · Jun 11, 2020 at 02:38 AM 0
Share

Hi, This is amazing, but I'm facing an important problem.

Let's say I have these items on my dropdown:

Item 10 Item 23 Item 33

If I type "3" on the input Field, it will show: Item 23 Item 33

But when I select the first result (item 23) it loads Item 10. If I select Item 33, it loads Item 23.

It's like changing the names, but keeping the old index.

Any guess on how to solve this?

Show more comments
avatar image serkantarakci · Apr 23, 2021 at 08:34 PM 0
Share

Well, how can I work with this without case sensitivity?

avatar image Hellium serkantarakci · Apr 23, 2021 at 08:48 PM 1
Share

https://stackoverflow.com/questions/8494703/find-a-substring-in-a-case-insensitive-way-c-sharp

avatar image
0

Answer by Jaeger47 · Jul 24, 2020 at 10:09 AM

Watch This https://www.youtube.com/watch?v=ncu_GdhPNVQ

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Satishkumar144 · Jul 07, 2021 at 04:30 PM 0
Share

How to add options by code ?

avatar image XIV_Dis Satishkumar144 · Aug 17, 2021 at 07:44 PM 0
Share

I wrote this script to use in Editor. Maybe you can use as an example and make some changes.

 #if UNITY_EDITOR
 using UnityEngine;
 using TMPro;
 using System.Collections.Generic;
 using System.Globalization;
 using System.Linq;
 
 [CreateAssetMenu(menuName = "DropDownPopulator")]
 public class PopulateDropDownSO : ScriptableObject
 {
     public string DropdownName;
 
     [SerializeField] private List<c_OptionData> countries = new List<c_OptionData>();
 
     [ContextMenu("Populate CountryOptionData With Names")]
     public void PopulateCountryOptionDataWithNames()
     {
         var nameList = GetCountryNames();
 
         for (int i = 0; i < nameList.Count; i++)
         {
             c_OptionData data = new c_OptionData();
             data.Text = nameList[i];
             countries.Add(data);
         }
     }
 
     [ContextMenu("Populate Dropdown With Countries")]
     public void PopulateWithCountryNames()
     {
         if (string.IsNullOrEmpty(DropdownName))
         {
             Debug.Log("DropdownName field is empty");
             return;
         }
         var dropdownGO = GameObject.Find(DropdownName);
         TMP_Dropdown dropdown;
 
         var result = false;
         if(dropdownGO != null)
         {
             var text = "Dropdown found. Parent name : " + dropdownGO.transform.parent.name;
             result = UnityEditor.EditorUtility.DisplayDialog("Dropdown Found", text, "Continue", "Cancel");
         }
         else
         {
             UnityEditor.EditorUtility.DisplayDialog("", "Couldnt find dropdown named : " + "dropdown", "Ok");
             return;
         }
         if (result)
         {
             dropdown = dropdownGO.GetComponent<TMP_Dropdown>();
 
             dropdown.ClearOptions();
             dropdown.AddOptions(CreateOptionDataFromCustom());
         }
     }
 
     private List<TMP_Dropdown.OptionData> CreateOptionDataFromCustom()
     {
         var optionDataList = new List<TMP_Dropdown.OptionData>();
 
         foreach (var item in countries)
         {
             var data = new TMP_Dropdown.OptionData(item.Text, item.Flag);
             optionDataList.Add(data);
         }
 
         return optionDataList;
     }
 
     private List<string> GetCountryNames()
     {
         var list = new List<string>();
         var countries = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(c =>
         new RegionInfo(c.LCID)).Distinct().OrderBy(c => c.EnglishName).ToList();
 
         list.Add("None");
         for (int i = 0; i < countries.Count; i++)
         {
             list.Add(countries[i].DisplayName);
         }
 
         return list;
     }
 
     [System.Serializable]
     public struct c_OptionData
     {
         public string Text;
         public Sprite Flag;
     }
 }    
 #endif
avatar image XIV_Dis XIV_Dis · Aug 17, 2021 at 07:58 PM 0
Share

--For some reason i couldnt edit previous reply.-- After creating a script (make sure script name matches with the class name) you need to create an Scriptable Object in Somewhere in Assets folder. For creating the SO go to Assets and right click, you will see an option named "DropDownPopulator". Then you can use methods that has [ContextMenu] attribute on it. To use methods select the SO and in the inspector right click to the name of it and you will see the described names of methods like "Populate Dropdown With Countries". To create an example you need an active TMP_Dropdown in your scene and you have to correctly type the name of it to Dropdown Name field.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

164 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Autocomplete Search (Search Suggestion) 5 Answers

How to put value on dropdown search like normal dropdown 0 Answers

FPS drop down after some time (Android) 1 Answer

Disable a dropdown option. 1 Answer

Dropdown.ClearOptions does not work 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges