Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
This question was closed Feb 11, 2020 at 12:37 PM by destro22 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by destro22 · Oct 15, 2019 at 02:55 PM · scripting probleminputfieldevent-handlingevent-listener

Why are InputFields not getting activated?

I don't understand if it's a bug in unity or wrong implementation of code but my inputFields are not getting activated when i click on the them. It activated for a fraction of a second and goes back to another inputfield. I have tried using handler in inspector and code as well but it is behaving in the same way.

I think its something to with event listeners that I am enabling using OnEnable(). Please throw some light on this.

What exactly am I doing wrong?

Thanks in advance. This is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class TabManager : MonoBehaviour
 {
     public InputField name1;
     public InputField Date;
     public InputField Month;
     public InputField Year;
     public InputField Phn;
 
 
 
     private void Update()
     {
        
        
     }
 
     void OnEnable()
     {
 
 
         
             name1.onEndEdit.AddListener(delegate { endEdit1(); });
 
 
 
 
             Date.onValueChanged.AddListener(delegate { valueChanged(); });
             Date.onEndEdit.AddListener(delegate { endEdit2(); });
 
 
 
 
 
 
 
             Month.onValueChanged.AddListener(delegate { valueChanged2(); });
             Month.onEndEdit.AddListener(delegate { endEdit3(); });
 
 
 
 
 
             Year.onValueChanged.AddListener(delegate { valueChanged3(); });
             Year.onEndEdit.AddListener(delegate { endEdit4(); });
 
         
 
     }
     //Called when Input is submitted
     private void endEdit1()
     {
         Date.ActivateInputField();
     }
     private void endEdit2()
     {
         Month.ActivateInputField();
     }
     private void endEdit3()
     {
         Year.ActivateInputField();
     }
     private void endEdit4()
     {
 
         Phn.ActivateInputField();
 
     }
     private void valueChanged()
     {
 
         if(Date.text.Length == 2)
         {
             Month.ActivateInputField();
         }
 
     }
     private void valueChanged2()
     {
 
         if (Month.text.Length == 2)
         {
             Year.ActivateInputField();
         }
 
     }
     private void valueChanged3()
 
     {
 
         if (Year.text.Length == 4)
         {
             Phn.ActivateInputField();
         }
 
     }
     void OnDisable()
     {
         
         name1.onEndEdit.RemoveAllListeners();
         Debug.Log("name");
 
         Date.onEndEdit.RemoveAllListeners();
         Date.onValueChanged.RemoveAllListeners();
         Debug.Log("Date");
 
         Month.onEndEdit.RemoveAllListeners();
         Month.onValueChanged.RemoveAllListeners();
         Debug.Log("Month");
 
         Year.onEndEdit.RemoveAllListeners();
         Year.onValueChanged.RemoveAllListeners();
         Debug.Log("Year");
     }
 
 
 }
 

I am using Unity 2018.4.9 with VS2017

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by HappiiGamer · Oct 15, 2019 at 07:23 PM

When you click an input field, you are selecting it, but at the same time you are calling OnEndEdit Listener on another field that was previously selected, which in turn selects another as per your code.

Comment
Add comment · Show 5 · 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 destro22 · Oct 16, 2019 at 07:09 PM 0
Share

@HappiiGamer is it possible to have multiple on enable() functions for each input field in a single script??

If it's possible how do we reference onenable() function for individual input field in a single script? Any ideas?

OR

Do I create a condition using eventsystem to detect the name of selected field and enable respective listener for each in the same onenable() function??

avatar image HappiiGamer destro22 · Oct 16, 2019 at 07:40 PM 0
Share

Could you tell me what you are trying to achieve? OnEnable is a method that is called in every object that inherits the $$anonymous$$onoBehaviour class, and it is automatically called whenever the GameObject becomes active in the scene.

avatar image destro22 HappiiGamer · Oct 17, 2019 at 07:53 AM 0
Share

@HappiiGamer in my scene when the app starts, there are input fields for name date month year and phnum, I am trying to switch to date when editing on name ends, then switch to month field if date's text length is ==2 or editing ends, similarly for month and year, then after year field done editing in should switch to phnum field. The above code definitely switches the field but the problem is if I select name after entering value in all fields it goes to name then activates year ins$$anonymous$$d of staying on name. It is as if listeners are switching because value changed conditions for the rest of the fields are true. It should not switch field on value changed if I simply select the field after entering all values.

Show more comments

Follow this Question

Answers Answers and Comments

210 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 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

Mouse drag horizontally and vertically is not working..? 0 Answers

Event from simultaneously pressing button + axis? 2 Answers

Trying to find what player inputed in Text Input field 1 Answer

Clicking won't throw object 2 Answers

How can I check if a key is down in scene view? 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