Author Topic: UIInput focus update  (Read 5331 times)

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
UIInput focus update
« on: September 09, 2013, 04:36:08 PM »
HI
Sorry I know this has been covered a little, but I'm still stuck.

First when I click into a box I want it to clear. (I've done this in the OnSelect function, but I'm not sure if its great code!)

Then if I type some text into a box, I want it to submit if I click outside the box, or click into another input box. Without having to press Enter.

I've tried so many ways. I still need my input text validated (i'm using UIInput Validator).

I'm not the best coder, so if you can help, please give me a fair amount of direction, many thanks for any help...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIInput focus update
« Reply #1 on: September 10, 2013, 07:05:26 AM »
  1. void OnSelect (bool isSelected)
  2. {
  3.     if (!isSelected)
  4.     {
  5.         UIInput input = GetComponent<UIInput>();
  6.         <do what you want with input.text>
  7.     }
  8. }

mtompson

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: UIInput focus update
« Reply #2 on: September 10, 2013, 03:34:27 PM »
thats great, many thanks.

I ended up putting:

  1.  
  2.         void OnSelect (bool isSelected)
  3.         {
  4.                 UIInput input = GetComponent<UIInput>();
  5.                
  6.                 if (isSelected){
  7.                                
  8.                         input.text = "";                //clear field on click
  9.                         input.label.text = "";  //clear field on click
  10.                 }
  11.                
  12.                 else{
  13.                                
  14.                         input.eventReceiver.SendMessage(input.functionName, input.text, SendMessageOptions.DontRequireReceiver);
  15.                 }
  16.         }
  17.  
  18.  

in a script attached to each UIinput box.

I know this is a personal choice thing, but basically I like to click in a field, it then empties, (if I change my mind and click out, it returns to previous value.) I then type and can either hit return, or click out and my new values update. This is probably not great for big text inputs, but for small number boxes it works well.
For example, I have two boxes next to each other for a direction & speed, its nicer to fill out one, then go straight over to fill the other...  :D
« Last Edit: September 11, 2013, 08:43:17 AM by mtompson »