Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Delayed ToolbarSearchField

Discussion in 'UI Toolkit' started by BinaryCats, Sep 2, 2019.

  1. BinaryCats

    BinaryCats

    Joined:
    Feb 8, 2016
    Posts:
    317
    Hi,

    I Have a ToolbarSearchField and I wish to perform an action when the user presses enter, but not escape. Essentially this is the behaviour of a delayed Text field

    according to this post by @antoine-unity
    https://forum.unity.com/threads/how...er-return-on-a-textfield.688579/#post-4609261

    However, this is not the behaviour for a TextField which is inside a ToolbarSearchField element. (The above information is correct for a standard TextField element)
    Code (CSharp):
    1.         SearchBar = root.Q<ToolbarSearchField>();
    2.         var text = SearchBar.Q<TextField>();
    3.         text.isDelayed = true;
    4.         text.RegisterCallback<ChangeEvent<string>>(evt =>
    5.         {
    6.             Debug.Log(evt.newValue);
    7.         });
    8.  
    The ChangeEvent will not fire until the user presses Enter ✔
    The ChangeEvent fires twice when the user pressed esc ❌
    • The first evt.newValue is an empty string
    • The second evt.newValue is the previous value of the search

    Why is this happening? And is there a way to make a delayed ToolbarSearchField function as described above?

    Any help will be much apricated, thanks in advance!
     
  2. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    486
    Hello, is it possible for you to report this as a bug?

    Thanks!
     
  3. BinaryCats

    BinaryCats

    Joined:
    Feb 8, 2016
    Posts:
    317
    Hi @hugobd , Thank you for your response

    bug reported: (Case 1181781)
     
  4. BinaryCats

    BinaryCats

    Joined:
    Feb 8, 2016
    Posts:
    317
    This issue has been resolved in 2020.1.0a2 now. Will the fix be back ported?