Author Topic: Problem with UIInput and onSubmit event  (Read 4852 times)

Rednaxela

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Problem with UIInput and onSubmit event
« on: October 10, 2013, 02:55:53 AM »
Hello, I'm using UIInput's onSubmit event to receive return button press on virtual keyboard on mobile devices.
The problem is that onSubmit event is raised even when I cancel input, e.g. pressing back key on Android.
I looked into UIInput class and found this check for mKeyboard.done property in Update function:
  1. if (mKeyboard.done)
  2.                         {
  3.                                 mKeyboard = null;
  4.                                 current = this;
  5.                                 if (onSubmit != null) onSubmit(mText);
  6.                                 if (eventReceiver == null) eventReceiver = gameObject;
  7.                                 eventReceiver.SendMessage(functionName, mText, SendMessageOptions.DontRequireReceiver);
  8.                                 current = null;
  9.                                 selected = false;
  10.                         }

So, event actually raised any time when keyboard is "done".
When I added checking for mKeyboard.wasCanceled property, then script works as expected.

  1. if (mKeyboard.done && !mKeyboard.wasCanceled)

Maybe there is a way to check if keyboard input was cancelled without modifying NGUI script?
Thanks in advance.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem with UIInput and onSubmit event
« Reply #1 on: October 10, 2013, 05:18:33 AM »
I will add that check, but keep in mind this will be in the next 3.X of NGUI, and judging by the code you posted it looks like you're using an earlier version.

Rednaxela

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Problem with UIInput and onSubmit event
« Reply #2 on: October 11, 2013, 07:37:50 AM »
Great! Thanks!

But can you please implement this feature in other way: either setting mText to null or adding additional bool parameter to onSubmit event, which will tell us that keyboard was cancelled?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem with UIInput and onSubmit event
« Reply #3 on: October 11, 2013, 07:51:27 AM »
Setting to null doesn't make sense. If you want to listen to cancel events, listen to OnSelect(false).