All functions and abilities missing in Web2 can be added using WebSDKUIControl Or WebSDKControl.
This code will detect just the enter key but can easily be expanded to return any key. Modify the JSModule code below.
The following blocks of code are String Constants
JSCode
var Company;
(function (Company) {
class KeyEventObj extends XojoWeb.XojoControl {
constructor(target, events) {
super(target, events);
}
callback(eventName, datum) {
datum = { data : datum };
this.triggerServerEvent(eventName, datum, true);
}
}
Company.KeyEventObj = KeyEventObj;
})(Company || (Company = {}));
JSModule
KeyEventModule = {
Init: function (idstr, controlid) {
$('#' + controlid + '_field').keyup(function(event) {
if (event.keyCode === 13) {
XojoWeb.getNamedControl(idstr).callback('EnterKey', XojoWeb.EncodeBase64(XojoWeb.getNamedControl(controlid).mValue));
}
});
}
};
Function ExecuteEvent(name as string, parameters as JSONItem) Handles ExecuteEvent as Boolean
Select Case EventName
Case "EnterKey"
RaiseEvent EnterKey(Data)
Return True
End Select
End Function
Function JavaScriptClassName() Handles JavaScriptClassName as String
Return "Company.KeyEventObj"
End Function
JSWebFile As WebFile Shared Property
Function SessionHead(session as WebSession) Handles SessionHead as String
Dim
Dim HTMLHeader As String
If JSWebFile = Nil Then
JSWebFile = New WebFile
JSWebFile.MIMEType = "text/javascript"
JSWebFile.Session = Nil
JSWebFile.Filename = "WebKeyJS.js"
JSWebFile.Data = JSCode //String constant
End If
HTMLHeader = "<script id=" + Chr(34) + "WebKeyJS" + Chr(34) + " src=" + Chr(34) + _
JSWebFile.URL + Chr(34) + " type=" + Chr(34) + "text/javascript" + Chr(34) + "></script>"
Return HTMLHeader
End Function
MainJSWebFile As WebFile Shared Property
Function SessionJavascriptURLs(session as WebSession) Handles SessionJavascriptURLs as String()
#pragma Unused session
Dim URLS(-1) As String
If MainJSWebFile = Nil Then
MainJSWebFile = New WebFile
MainJSWebFile.MIMEType = "text/javascript"
MainJSWebFile.Session = Nil
MainJSWebFile.Filename = "WebKeyJSFunctions.js"
MainJSWebFile.Data = JSModule //String constant
End If
URLS.Append(MainJSWebFile.URL)
Return URLS
End Function
Sub Shown() Handles Shown
Dim CMDToSend As String
CMDToSend = "KeyEventModule.Init(" + Chr(39) + Self.ControlID + Chr(39) + "," + _
Chr(39) + Self.ControlID + Chr(39) + ");"
Self.ExecuteJavaScript(CMDToSend)
End Sub
I have used this to extend a WebTextField to add the ability to return the data in the text field when the enter key is pressed. Web2 is the best!