Class
WebTextField
Description
A single line, editable text control. The web equivalent of the DesktopTextField control.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
Script As String |
|||
Events
Name |
Parameters |
Returns |
---|---|---|
hitItem As WebMenuItem |
||
Enumerations
WebTextField.FieldTypes
FieldTypes
Specifies the various types of data entry to which the TextField can be constrained on browsers that support such constraints.
Enum |
Description |
---|---|
Normal |
Allows any alphanumeric data to be entered. |
Password |
Allows any alphanumeric data to be entered but masks the entry with bullets. |
Allows only characters valid in an email address and enforces that the entry be in valid email format. |
|
Number |
Allows the entry of numbers and the decimal character only. |
Telephone |
Allows only characters valid in a telephone number and enforces that the entry be in valid phone number format. |
URL |
Allows only characters valid in a URL and enforces that the entry be in valid URL format. |
Property descriptions
WebTextField.AllowAutoComplete
AllowAutoComplete As Boolean
If True, enables the autocomplete feature to complete text entries. The default is False.
Me.AllowAutoComplete = True
WebTextField.AllowSpellChecking
AllowSpellChecking As Boolean
If True, on browsers that support spellchecking, the value of the control will be spell-checked.
This example is in the Opening event of a TextArea:
Me.AllowCheckSpelling = True
WebTextField.Caption
Caption As String
The caption of a control.
This property can be set inside the IDE or programmatically.
This code sets the caption of the control to "OK".
Me.Caption = "OK"
This code in the Pressed event handler for a WebButton changes the text of the button each time it is pressed:
If Me.Caption = "Blue" Then
Me.Caption = "Red"
Else
Me.Caption = "Blue"
End If
WebTextField.ContextualMenu
ContextualMenu As WebMenuItem
If you assign a WebMenuItem to the control, it will be displayed when the user right-clicks the control.
On a WebPage, you can disable/remove the default contextual menu by an empty WebMenuItem class object to this property.
This code populates a contextual menu in the Shown event of the control.
Var menu As New WebMenuItem
menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu
The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:
Select Case hitItem.Text
Case "One"
MessageBox("One")
Case "Two"
MessageBox("Two")
Case "Three"
MessageBox("Three")
End Select
WebTextField.ControlID
ControlID As String
Identifies the control on a per session basis.
This property is read-only.
WebTextField.Enabled
Enabled As Boolean
When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.
In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.
Disable a button when a check box value changes:
If AllowSaveCheckBox.Value Then
SaveButton.Enabled = True
Else
AllowSaveButton.Enabled = False
End If
WebTextField.FieldType
FieldType As FieldTypes
Specifies the type of data the TextField will handle automatically.
It is up to the browser to decide when to support this. For example, Safari tends to support it only for mobile.
See FieldTypes for a list of possible types.
Allow numbers only:
Me.FieldType = WebTextField.FieldTypes.Number
WebTextField.Height
Height As Integer
The height (in pixels) of the control.
WebTextField.Hint
Hint As String
Text that appears inside the control providing a hint about what to enter.
On Windows and Linux, the Hint only appears when the control does not have focus.
This example is in the Opening event of the control:
Me.Hint = "Last Name"
WebTextField.Indicator
Indicator As Indicators
The color scheme for the control.
WebTextField.Left
Left As Integer
The position of the left side of the WebUIControl in pixels, relative to the web page.
WebTextField.LockBottom
LockBottom As Boolean
Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning web page.
WebTextField.LockHorizontal
LockHorizontal As Boolean
LockHorizontal overrides LockLeft and LockRight. It allows you to proportionally lock a control's position to the center of its parent control (or web page).
For example, if you place a control in the center of the page and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.
WebTextField.LockLeft
LockLeft As Boolean
Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning web page.
WebTextField.LockRight
LockRight As Boolean
Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning web page.
WebTextField.LockVertical
LockVertical As Boolean
LockVertical overrides LockTop and LockBottom. It allows you to proportionally lock a control's position to keep it centered within the parent control or web page.
For example, if you place a control in the center of the page, and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.
WebTextField.MaximumCharactersAllowed
MaximumCharactersAllowed As Integer
The maximum number of characters allowed in the input area of the control.
The value of zero does not limit text. This property works for normal text entry, copy and paste, and drag and drop.
This code is in the Opening event of the control. It prohibits more than the specified number of characters:
Me.MaximumCharactersAllowed = 10
WebTextField.Name
Name As String
The name of the control.
This property is read-only.
WebTextField.PanelIndex
PanelIndex As Integer
If the control has been placed on a WebTabPanel or WebPagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
The first panel is numbered zero. If the control has been placed on a panel of a WebTabPanel or WebPagePanel control, it returns the panel number. If the control is not on a WebPagePanel or WebTabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
If you are looking to change the currently selected panel (page/tab), use SelectedPanelIndex.
This code displays the panel index of the control that is on the page.
MessageBox(Me.SelectedPanelIndex.ToString)
WebTextField.Page
Page As WebPage
Identifies the web page that contains the control.
This property is read-only.
WebTextField.Parent
Parent As WebView
Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.
This property is read-only.
WebTextField.ReadOnly
ReadOnly As Boolean
If True, the text of the control cannot be modified.
This example is in the Opening event of the control.
Me.ReadOnly = True
WebTextField.TabIndex
TabIndex As Integer
The WebTextField's control's position in the Tab Order. The control with a TabIndex of 0 is the first WebUIControl to get the focus when the page opens in the browser.
This example sets the control's TabIndex.
Me.TabIndex = 2
WebTextField.Text
Text As String
Specifies the text displayed in the control.
To set the Text for a WebLabel:
Label1.Text = "Name:"
To set the Text for a WebTextField:
TextField1.Text = "Bob Roberts"
To set the Text for a WebTextArea:
TextArea1.Text = "1 Main Street" + EndOfLine + "Anytown, NY 12345"
WebTextField.TextAlignment
TextAlignment As TextAlignments
The alignment of the text.
WebTextField.Tooltip
Tooltip As WebToolTip
Text of a message displayed as a tooltip.
The tip is displayed when the user places the mouse on the control and leaves it there.
This code in the Shown event of a Button sets the tooltip:
Me.Tooltip = "Save changes"
WebTextField.Top
Top As Integer
The top of the control in local coordinates relative to the web page.
WebTextField.Visible
Visible As Boolean
If True, the control is drawn. If False, it's not.
Hide a control based on a checkbox setting:
If ShowEmailCheckbox.Value Then
EmailField.Visible = True
Else
EmailField.Visible = False
End If
WebTextField.Width
Width As Integer
The width (in pixels) of the web control.
This code in the Shown event handler increases the size of the control:
Me.Width = Me.Width + 50
Method descriptions
WebTextField.Close
Close
Removes the control from the page.
WebTextField.ExecuteJavaScript
ExecuteJavaScript(Script As String)
Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.
The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the EcmaScript 6 documentation.
This code in the Pressed event of a Button displays an alert using JavaScript:
Me.ExecuteJavaScript("alert('Hello!');")
This code will select the text in a WebTextField (or WebTextArea):
WebTextField1.ExecuteJavascript("document.getElementById('" + _
WebTextField1.ControlID + "_inner').select();")
WebTextField.Style
Style As WebStyle
Style(Assigns style As WebStyle)
The WebStyle for the control.
In the Pressed event of a WebButton, set the text to bold:
Var style As New WebStyle
style.Bold = True
Me.Style = style
WebTextField.GotoURL
GotoURL(Url As String, inNewWindow As Boolean = False)
Opens the passed URL in place of the current web page or downloads a file. If InNewWindow is True, the browser is asked to open the URL in a new window.
If the browser has popup windows disabled and InNewWindow is True, the method silently fails and the page is not shown.
If InNewWindow is False, the running web app is replaced with the specified URL. If you want to display an external web site within your web app, use the WebHTMLViewer control.
Display a web site in a new popup window:
Me.GotoURL("http://www.wikipedia.org", True)
WebTextField.SelectAll
SelectAll
WebTextField.SetFocus
SetFocus
Sets the focus to the Control.
This code checks for a required value when a button is pressed:
If UserNameField.Text.IsEmpty Then
MessageBox("Please enter your UserName.")
UserNameField.SetFocus
Return
End If
WebTextField.UpdateBrowser
UpdateBrowser
Forces the current values of the control to be sent to the browser.
This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.
This code iterates through a RowSet of database rows, updates a ProgressBar and then forces the updated ProgressBar to be sent to the browser via UpdateBrowser.
ProgressBar1.MaximumValue = SalesData.RowCount
For Each row As DatabaseRow in SalesData
AnalyzeSales(row)
ProgressBar1.Value = ProgressBar1.Value + 1
ProgressBar1.UpdateBrowser
Next
Event descriptions
WebTextField.Closed
Closed
The control has been removed from the browser either because the page has closed or the control's Close method was called.
WebTextField.ContextualMenuSelected
ContextualMenuSelected(hitItem As WebMenuItem)
Called when a contextual menu item is selected. This selected item is contained in hitItem.
This code populates a contextual menu in the Opening event of a WebToolbar:
Var menu As New WebMenuItem
menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu
The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:
Select Case hitItem.Text
Case "One"
MessageBox("One")
Case "Two"
MessageBox("Two")
Case "Three"
MessageBox("Three")
End Select
WebTextField.FocusLost
FocusLost
The control has lost the focus.
WebTextField.FocusReceived
FocusReceived
The control has received the focus and has a selection rectangle around it.
WebTextField.Hidden
Hidden
The control is about to become no longer visible. This could be because the page is being closed, is being replaced as the foreground page by another page or because the control or a parent control's Visible property has been set to False.
Note
This event is equivalent to the DesktopWindow.Deactivated event in a desktop app.
WebTextField.Opening
Opening
The control has been created and the page is opening but has not been sent to the browser yet.
The Opening event handler can be used to initialize non-visual properties and settings for controls.
In most cases, you should use the Shown event to initialize controls.
WebTextField.Shown
Shown
The control has appeared on the currently displayed page. This could be because its parent page just finished loading, its parent page has come to the foreground or the control is now visible having been previously invisible because it or its parent control's Visible property has been set to True.
Use the Shown event for initializing your controls or doing anything that would interact with other controls or user interface elements on the web page instead of the Opening event.
Note
This event is the web equivalent to the DesktopWindow.Activated event.
WebTextField.TextChanged
TextChanged
The text in the control has changed. The event fires only when the user has stopped typing for a short period.
Currently in both Google Chrome and Microsoft Edge, the autofill feature of these browsers does not trigger this event.
This event handler is not called for WebLabel since its Value property cannot be modified by the user.
Display the text typed by the user:
MessageBox(Me.Text)
Sample code
Display text in the textfield:
TextField1.Text = "Hello, World!"
Compatibility
Web projects on all supported operating systems.
See also
WebTextControl parent class; WebLabel, WebTextArea, WebSearchField