Dialog Boxes In Nativescript

The dialog boxes are some predefine interface that comes up on some events. 

Nativescript provides 5 types of dialog boxes

  1. Alert
  2. Confirm
  3. Prompt
  4. Login
  5. Action

In order to use dialog boxes in the Nativescript, we have to import 'Dialogs' from '@nativescript/core'

import { Dialogs } from "@nativescript/core";

1. Alert - 

 Dialogs.alert({
        title:"alert",
        message:"Message",
        okButtonText:"Button name"
      })
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      })

2. Confirm - 

Dialogs.confirm({
        title:"Confirm Box Titile",
        message:"Message",
        okButtonText:"Button Text",
        cancelButtonText:"cancel button",
        neutralButtonText:"nutral text"
      })
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      })

3.Prompt -

 Dialogs.prompt({
        title:"Prompt Box Title",
        message:"Message",
        okButtonText:"Button Text",
        cancelButtonText:"cancel button text",
        neutralButtonText:"Neutral button text",
        defaultText:"default button text",
       inputType:inputType.password
      })
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      })

4. login -

 Dialogs.login({
        title:"Login Box Title",
      message:"Message",
      okButtonText:"Button Text",
      cancelButtonText:"cancel button text",
      neutralButtonText:"Neutral button text",
      userName:"Username text",
      password:"password text"
      })
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      })

5 Action -

 Dialogs.action({
        message:"Action Box Title",
        cancelButtonText:"cancel button text",
       actions:["button1","button2","button3"]
        })
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        })

Add comment