HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: GUITextInputBox clears input when ENTER key is pressed  (Read 3119 times)

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
GUITextInputBox clears input when ENTER key is pressed
« on: Sep 15, 14, 12:26:03 PM »

I noticed that GUITextInputBox clears input when ENTER key is pressed. Isn't this default behaviour a little bit suspicious, especially considering that there is no trivial way to override this?

Right now i am storing the value in HE_onKeyDown()  and then force it back in HE_onKeyUp, but it looks ugly, for example:
 
Code: [Select]
method HE_onKeyDown (args references Class GUIKeyboardEvent)
//enter key
  if args.keyCode == 13
    me.MUD_GUICommonTextInputEnterKeyValue = me.value
  .
.


method HE_onKeyUp (args references Class GUIKeyboardEvent)
//enter key
  if args.keyCode == 13
    me.value = me.MUD_GUICommonTextInputEnterKeyValue
  .
.

So my questions are:
1. Is this default behaviour suspicious? Why am i claiming that it is suspicious? For example go to www.google.com and enter some text in their textinput and press ENTER. The entered text will not get cleared.

2. Are there any better(easier) ways to handle this? Please provide code examples.




Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: GUITextInputBox clears input when ENTER key is pressed
« Reply #1 on: Sep 15, 14, 03:03:44 PM »

That is due to the historySize property.  That dictates how many previous entries it remembers, which allow you to use the up/down arrows to repeat previous entries, as is standard for a chat entry bar.  If you don't want that, set historySize to 0 and it will not clear when pressing enter, though it will not remember previous entries, either.
« Last Edit: Sep 15, 14, 03:07:53 PM by ScottZarnke »
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

AWW_boss

  • General Accounts
  • *
  • Posts: 846
  • gdfgd
    • View Profile
Re: GUITextInputBox clears input when ENTER key is pressed
« Reply #2 on: Sep 15, 14, 03:33:05 PM »

historySize solved it! Thanks for the solution Scott.
Logged

JoshHalls

  • Founding Professional
  • *****
  • Posts: 335
    • View Profile
    • The Repopulation
Re: GUITextInputBox clears input when ENTER key is pressed
« Reply #3 on: Sep 15, 14, 03:33:54 PM »

Oh how much fun I had figuring that one out :-).
Logged
Co-Owner/Programmer - The Repopulation

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: GUITextInputBox clears input when ENTER key is pressed
« Reply #4 on: Sep 15, 14, 04:49:07 PM »

You're welcome, AWW_boss.

Quote
Oh how much fun I had figuring that one out :-).
I hope that wasn't just recently.

For what its worth, a search of GUITextInputBox on the hero wiki shows it there, too:
http://hewiki.heroengine.com/wiki/GUITextInputBox_FAQ
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

keeperofstars

  • General Accounts
  • *
  • Posts: 998
    • View Profile
    • StarKeeper Online
Re: GUITextInputBox clears input when ENTER key is pressed
« Reply #5 on: Sep 15, 14, 11:09:04 PM »

Just remember you still are getting the text input happening. So this is more of not a resolve for the real issue, which is you not handling the text input on the enter, but trying to work around it.

As far as how websites do it they temp cache the value and add it back when the page refreshes, either javascript, a cookie, or the server maintains the value. So really it's no different here, you need to store the value on enter and re-supply it on load again. Thing is GUI in this case doesn't have a load, but there are other means of checking when an event has finished, aka the textinput event.

So just remember, though you are still having the textinput box preforming actions on enter. Even if the value returns back to the box, cause you set history to zero. The input is still firing, so make sure you deal with that part of it.

Logged
[img]http://screencast.com/t/x7btcSSyp3h0[\img]