Source language: Translate to:

A fix for "Press Enter to Submit"

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

A fix for "Press Enter to Submit"

Postby fkapnist » Fri Oct 09, 2015 12:05 pm

Many users like to press "Enter" to submit a text string that they typed into a text field, although there is usually a button next to it that does the same thing. You can specify a Short Cut Key to submit your text string ("Enter' is actually not on the drop down list, but if you press enter, it will appear as your Short Cut Key selection).

But what if you have two or more text fields and you want them all to submit data when you press enter? Since you can only set "Enter" once as a short cut key how will Neobook know which text field you want to submit? Below is a short PUB code that does it by setting a variable when a text field is in "gain focus." The variable tells the Enter press what action to perform.




Code: Select all
NBW Publication Source File
(C)2015 NeoSoft Corp.
Title=Untitled NeoBook Publication
Language=US
NeoBookVer=5.80
ScreenColors=16777216
ScreenWidth=640
ScreenHeight=480
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
SplashProps=3
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
ReqExLevel=1
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That's not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That's not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files...
L_SENDEMAIL=Sending Mail...
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait...
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=0
PageColor=16777215
PageGradient1=16711680
PageGradient2=255
PageGradientDir=1
WallpaperStyle=0
ObjectType=9
Name=TextEntry1
X=159
Y=132
W=261
H=39
Anchor=0
Text=test text 1
VarName=[TextEntry1]
Align=1
EditLen=0
ObjSetFocusAction=SetVar "[EnterFocus]" "1"
ObjLoseFocusAction=SetVar "[EnterFocus]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=3
Name=PushButton1
X=431
Y=132
W=54
H=38
Anchor=0
Text=GO
Align=2
ImageStyle=0
ObjAction=AlertBox "" "[TextEntry1]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=9
Name=TextEntry2
X=155
Y=214
W=261
H=39
Anchor=0
Text=test text 2
VarName=[TextEntry2]
Align=1
EditLen=0
ObjSetFocusAction=SetVar "[EnterFocus]"  "2"
ObjLoseFocusAction=SetVar "[EnterFocus]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=3
Name=PushButton2
X=431
Y=214
W=54
H=38
Anchor=0
Text=GO
Align=2
ImageStyle=0
ObjAction=AlertBox "" "[TextEntry2]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=3
Name=PushButton3
X=-142
Y=180
W=130
H=35
Anchor=0
Text=Enter key options
Align=2
Key=13
ImageStyle=0
ObjAction=If "[EnterFocus]" "=" "1"¶AlertBox "" "[TextEntry1]"¶EndIf¶¶If "[EnterFocus]" "=" "2"¶AlertBox "" "[TextEntry2]"¶EndIf
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6


:idea:

.
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: A fix for "Press Enter to Submit"

Postby mishem » Fri Oct 09, 2015 1:14 pm

Paste this code in the button "Enter key options"

Code: Select all
GetObjectInfo "[FocusedObject]" "Caption" "[Text]"
AlertBox "" "[Text]"


Could it be better?
mishem
 
Posts: 575
Joined: Mon Oct 08, 2012 1:51 pm

Re: A fix for "Press Enter to Submit"

Postby fkapnist » Fri Oct 09, 2015 1:48 pm

mishem wrote:Paste this code in the button "Enter key options"

Code: Select all
GetObjectInfo "[FocusedObject]" "Caption" "[Text]"
AlertBox "" "[Text]"


Could it be better?



Thanks mishem. That is a good example if you want the action to be a caption alert or message. But the Enter action can in fact be anything....
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: A fix for "Press Enter to Submit"

Postby fkapnist » Fri Oct 09, 2015 1:57 pm

fkapnist wrote:
mishem wrote:Paste this code in the button "Enter key options"

Code: Select all
GetObjectInfo "[FocusedObject]" "Caption" "[Text]"
AlertBox "" "[Text]"


Could it be better?



Thanks mishem. It reduces the code a lot if you have several text fields. But keep in mind that objects other than text fields can be focused too, and they will not respond the way we want. That is a good example if you want the action to be a caption alert or message. But the "Press Enter" action can in fact be anything....
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: A fix for "Press Enter to Submit"

Postby mishem » Fri Oct 09, 2015 3:37 pm

I was just reminded that there is a global variable [FocusedObject].
:)
mishem
 
Posts: 575
Joined: Mon Oct 08, 2012 1:51 pm

Re: A fix for "Press Enter to Submit"

Postby fkapnist » Fri Oct 09, 2015 5:29 pm

mishem wrote:I was just reminded that there is a global variable [FocusedObject].
:)


I was also wondering where that variable came from
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron