Text fields - detecting the enter key

BlitzMax Forums/BlitzMax Programming/Text fields - detecting the enter key

taxlerendiosk(Posted 2005) [#1]
How do I do this? The example in the docs only shows you how to do it a silly way with a button. Surely there's a proper way?


Chris C(Posted 2005) [#2]
SetGadgetFilter (theres even an example!)


taxlerendiosk(Posted 2005) [#3]
Heh. Might well have an example but I had no idea "filters" were even related. Anyway, thanks!

Edit: Changed the SetGadgetFilter example from a text area from a text field and judging from the output it still isn't detecting Enter. What's going on?


skidracer(Posted 2005) [#4]
It is because we are now using a dialog control in windows which manages the tabbing between gadgets and unfortunately swallows all traces of the Enter key being pressed, hence the need for the silly button, which can be hidden with dimensions 0,0,0,0 if you must...


taxlerendiosk(Posted 2005) [#5]
Yeah, I must. But if I have multiple fields in the same gadget how am I supposed to know which text field it's from since the event hits the button? I tried ActiveGadget() but that didn't work.


skidracer(Posted 2005) [#6]
You don't (unless you keep your own LastModifiedTextField variable), and you will be confusing the average windows user if you treat the enter key in such a manner because the standard behavior for a Windows form / dialog is always for the enter key to Post or OK the form.

That said, a lostfocus event for textfields may be needed in MaxGUI so you can also validate your fields when users tab to the next one, in the meantime you need to either validate your textfields as they are modified or just validate all of them when the users goes OK or perhaps / maybe take over the Enter key entirely with a SetHotKeyEvent.


taxlerendiosk(Posted 2005) [#7]
It's not a form. It's some file path URLs which you can see/edit manually aswell as hitting a button to open a file requester and select it that way. I wanted it so if you edit it manually you have to hit "enter" for it to verify the file.


Chris C(Posted 2005) [#8]
In most of the bespoke java database apps I've made, my clients have overwhelmingly requested that enter/return should validate and tab on to the next control...
(its much quicker for data entry)

It might not be "standard" but its a *very* popular way of doing it...


Chris C(Posted 2005) [#9]
:0 oh no it seems to eat escape too!


taxlerendiosk(Posted 2005) [#10]
Also if it was something like entering float numbers for something that is graphically represented on a canvas, personally I'd prefer it not try to update the graphics as the value changes with each keystroke but to wait until enter is hit.


Chris C(Posted 2005) [#11]
i've solved it by using a textarea shaped like a textfield
I filter out return (return 0 on return down) so it doesnt
grow (but you could do your validation here too)
and escape to quit

it does mean you have to detect the tab key and activate
the next gadget, and i'm not sure if activegadget is working...

hope that helps


taxlerendiosk(Posted 2005) [#12]
Yeah, that could work. I haven't tried it but I suppose another solution could be to encapsulate the field inside its own panel with an ok_button. That would probably kill tabbing completely, though...


Chris C(Posted 2005) [#13]
I managed to solve it completely but to do the focus tabbing
I had to have 2 filter routines 1 for each component

I couldnt get activegadget to work at all...

here I'm filtering return out so that it doesnt add
another line to the text area

escape quits the application

and tab switches between the two "text fields"


Function filter_r1:Int(event:TEvent,context:Object)

	If event.id=EVENT_KEYDOWN Then
		If event.data=27 Then End
		If event.data=13 Then Return 0
		If event.data=9 Then
			ActivateGadget textfield_r2
			Return 0
		EndIf
	EndIf
	
	If event.id=EVENT_KEYCHAR And event.data=9 Then Return 0
				
	Return 1

End Function


Function filter_r2:Int(event:TEvent,context:Object)

	If event.id=EVENT_KEYDOWN Then
		If event.data=27 Then End
		If event.data=13 Then Return 0
		If event.data=9 Then
			ActivateGadget textfield_r1
			Return 0
		EndIf
	EndIf

	If event.id=EVENT_KEYCHAR And event.data=9 Then Return 0

	Return 1

End Function




i have 2 textareas 1 line high called textfield_r1 and textfield_r2

oh you'll need to check that the length of the entered input
doesnt exceede the width of the component
or the scrollbars obscure everthing


taxlerendiosk(Posted 2005) [#14]
You could do that by filtering EVENT_KEYCHAR to return 0 if TextAreaLen exceeds some specified amount, right?


Chris C(Posted 2005) [#15]
yep, I guess that would be the way to go...