UI for grabbing the users attention, prompting for confirmation, choice, input, or credentials.
NativeScript offers various dialogs, available via the Dialogs import from @nativescript/core, or globally.
ts
import { Dialogs } from'@nativescript/core'Dialogs.alert(options)Dialogs.action(options)Dialogs.confirm(options)Dialogs.prompt(options)Dialogs.login(options)// is the same as:alert(options)action(options)confirm(options)prompt(options)login(options)
All dialogs take a DialogOptions object with the properties:
title: Sets the dialog title.
message : Sets the dialog message.
cancelable (Android only): Sets if the dialog can be canceled by taping outside of the dialog.
theme (Android only): Sets the theme of the Dialog. Usable themes can be found in R.style
showConfirm() { Dialogs.confirm({ title: 'Confirm!', message: 'Are you sure you want to do this?', okButtonText: 'Yes', cancelButtonText: 'No', neutralButtonText: 'Cancel', }).then((result) => { console.log(result) })}
tsx
Dialogs.confirm({ title: 'Confirm!', message: 'Are you sure you want to do this?', okButtonText: 'Yes', cancelButtonText: 'No', neutralButtonText: 'Cancel',})
tsx
Dialogs.confirm({ title: 'Confirm!', message: 'Are you sure you want to do this?', okButtonText: 'Yes', cancelButtonText: 'No', neutralButtonText: 'Cancel',})
svelte
Dialogs.confirm({title: 'Confirm!',message: 'Are you sure you want to do this?',okButtonText: 'Yes',cancelButtonText: 'No',neutralButtonText: 'Cancel',})
vue
Dialogs.confirm({ title: 'Confirm!', message: 'Are you sure you want to do this?', okButtonText: 'Yes', cancelButtonText: 'No', neutralButtonText: 'Cancel',}).then((result) => { console.log(result)})
showPrompt() { Dialogs.prompt({ title: 'Prompt!', message: 'Enter the name of this framework:', defaultText: 'NativeScript', okButtonText: 'OK', neutralButtonText: 'Cancel',// cancelable: true,// cancelButtonText: 'Cancel',// capitalizationType: 'none',// inputType: 'email', }).then((result) => { console.log(result) })}
tsx
Dialogs.prompt({ title: 'Prompt!', message: 'Enter the name of this framework:', defaultText: 'NativeScript', okButtonText: 'OK', neutralButtonText: 'Cancel',// cancelable: true,// cancelButtonText: 'Cancel',// capitalizationType: 'none',// inputType: 'email',})
tsx
Dialogs.prompt({ title: 'Prompt!', message: 'Enter the name of this framework:', defaultText: 'NativeScript', okButtonText: 'OK', neutralButtonText: 'Cancel',// cancelable: true,// cancelButtonText: 'Cancel',// capitalizationType: 'none',// inputType: 'email',})
svelte
Dialogs.prompt({title: 'Prompt!',message: 'Enter the name of this framework:',defaultText: 'NativeScript',okButtonText: 'OK',neutralButtonText: 'Cancel',// cancelable: true,// cancelButtonText: 'Cancel',// capitalizationType: 'none',// inputType: 'email',})
vue
Dialogs.prompt({ title: 'Prompt!', message: 'Enter the name of this framework:', defaultText: 'NativeScript', okButtonText: 'OK', neutralButtonText: 'Cancel', // cancelable: true, // cancelButtonText: 'Cancel', // capitalizationType: 'none', // inputType: 'email',}).then((result) => { console.log(result)})
A dialog for prompting the user for input.
defaultText: Sets the default text to display in the input box.
inputType: Sets the prompt input type: email, decimal, phone, number, text, password, or email
capitalizationType: Sets the prompt capitalization type. Avalable options: none, allCharacters, sentences, or words.