Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

(B20) InputField onValidate, onCancel?

Discussion in 'UGUI & TextMesh Pro' started by Diablo404, Oct 7, 2014.

  1. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    Hi all,

    I've searched all the day long to make this one.

    I'd like to be able, in script, to add listeners to validation or cancelation of the input field after the user typed some text. I tried with onSubmit but as lots of already said, it's not working for every cases.

    And I tried to play with the ICancelHandler but didn't get better result.

    Any help is welcome.
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    There is no message for cancellation of the input field but there is the onValidateInput delegate that you can assign a listener to
     
  3. Diablo404

    Diablo404

    Joined:
    Mar 15, 2013
    Posts:
    136
    Thanks, I'll try to play with OnDeselect.

    Regarding onValidateInput, I can't add a listener to it.

    Code (CSharp):
    1. void Awake()
    2.     {
    3.        
    4.         GetComponent<InputField>().onValidateInput.AddListener( Validated );
    5.  
    6.    
    7.  
    8.     }
    9.    
    10.     void Validated(string _value, int index, char car )
    11.     {
    12.         print ("validated" );
    13.     }
    Throws the error :

    Assets/Plugins/Test.cs(12,60): error CS1061: Type `UnityEngine.UI.InputField.OnValidateInput' does not contain a definition for `AddListener' and no extension method `AddListener' of type `UnityEngine.UI.InputField.OnValidateInput' could be found (are you missing a using directive or an assembly reference?)
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    right because its not a UnityEvent its a C# Delegate. you need to do

    GetComponent<InputField>().onValidateInput = Validated;