TextField
<TextField>
is an input component that creates an editable single-line box.
<TextField>
extends TextBase
and EditableTextBase
which provide additional properties and events.
<TextField
hint="Enter Date"
secure="false"
keyboardType="datetime"
returnKeyType="done"
autocorrect="false"
maxLength="10"
[text]="name"
(returnPress)="onReturnPress($event)"
(focus)="onFocus($event)"
(blur)="onBlur($event)"
>
</TextField>
import { Component } from '@angular/core'
import { TextField, Utils } from '@nativescript/core'
@Component({
moduleId: module.id,
templateUrl: './usage.component.html'
})
export class UsageComponent {
name = ''
onReturnPress(args) {
// returnPress event will be triggered when user submits a value
const textField = args.object as TextField
// Gets or sets the placeholder text.
console.log(textField.hint)
// Gets or sets the input text.
console.log(textField.text)
// Gets or sets the secure option (e.g. for passwords).
console.log(textField.secure)
// Gets or sets the secure without autofill for iOS 12+ (e.g. for passwords).
console.log(textField.secureWithoutAutofill)
// Gets or sets the soft keyboard type. Options: "datetime" | "phone" | "number" | "url" | "email"
console.log(textField.keyboardType)
// Gets or sets the soft keyboard return key flavor. Options: "done" | "next" | "go" | "search" | "send"
console.log(textField.returnKeyType)
// Gets or sets the autocapitalization type. Options: "none" | "words" | "sentences" | "allcharacters"
console.log(textField.autocapitalizationType)
// Gets or sets a value indicating when the text property will be updated.
console.log(textField.updateTextTrigger)
// Gets or sets whether the instance is editable.
console.log(textField.editable)
// Enables or disables autocorrection.
console.log(textField.autocorrect)
// Limits input to a certain number of characters.
console.log(textField.maxLength)
Utils.setTimeout(() => {
textField.dismissSoftInput() // Hides the soft input method, usually a soft keyboard.
}, 100)
}
onFocus(args) {
// focus event will be triggered when the users enters the TextField
const textField = args.object as TextField
}
onBlur(args) {
// blur event will be triggered when the user leaves the TextField
const textField = args.object as TextField
}
}
<TextField hint="Enter text" color="orangered" backgroundColor="lightyellow" />
<TextField :text="textFieldValue" hint="Enter text..." />
<TextField>
provides two-way data binding using v-model
.
<TextField v-model="textFieldValue" />
<textField text="{textFieldValue}" hint="Enter text..." />
<textField>
provides two-way data binding using bind
.
<textField bind:text="{textFieldValue}" />
<textField text={textFieldValue} hint="Enter text..." />
Props
Name | Type | Description |
---|---|---|
|
|
Gets or sets the value of the field. |
|
|
Gets or sets the placeholder text. |
|
|
Make the field disabled or enabled.
Default value is |
|
|
When |
|
|
Limits input to the specified number of characters. |
|
|
Hides the entered text when |
|
|
Prevent iOS 12+ auto suggested strong password handling (iOS Only) |
|
|
Shows a custom keyboard for easier text input.
+ Valid values: |
|
|
Gets or sets the label of the return key.
+ Valid values: |
|
|
Enables or disables autocorrect. |
|
Gets or sets the auto capitalization type. |
|
|
|
Gets or sets letter space style property. |
|
|
Gets or sets line height style property. |
|
|
Gets or sets the text alignment. |
|
|
Gets or sets the text decoration. |
|
|
Gets or sets the text transform. |
|
|
Gets or sets white space style property. |
|
|
Additional inherited properties are not shown. Refer to the API Reference |
Events
Name | Description |
---|---|
|
Emitted when the text changes. |
|
Emitted when the return key is pressed. |
|
Emitted when the field is in focus. |
|
Emitted when the field loses focus. |