Search Unity

Clear TextField on click?

Discussion in 'Immediate Mode GUI (IMGUI)' started by op_moore, Nov 6, 2011.

  1. op_moore

    op_moore

    Joined:
    Feb 4, 2011
    Posts:
    26
    Hi, :)

    I want to clear a textfield on focus.

    Any examples?

    Tried searching and haven't found any clear answers.

    Thanks in advance!

    Oliver :)
     
  2. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    put in default text like 'Enter Name', and then when a user clicks on it test to see if it still says 'Enter Name' and if it does, clear the text?

    I think that would work...

    although how you'd get when a user clicks on the textfield. GUI.Changed might register a click on a textfield
     
  3. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    I have run into a need to do this myself, and discovered that GUI.Changed does not get a click on textfield.

    Anyone else have any ideas?

    I'm thinking to just check if the Event.current. mouse button is clicked within the rect of my textfield. But this is for iOS, is there a way to get touch events through the Event class on iOS?
     
  4. Lythande

    Lythande

    Joined:
    Jul 23, 2017
    Posts:
    6
    Hello techmage, I've the same problem ...
    Have you found a solution?
     
  5. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    102
    You can do it with something like that:
    Code (CSharp):
    1. TextEditor t = TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
    2. t.SelectAll();
    3. t.Delete();
    I haven't test it!