Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

NativeDialog

Global object for invoking native system dialogs. More...

Import Statement: import Felgo 4.0
Inherits:

Item

Methods

  • alert(string title, string description, function callback, string okButtonTitle, string cancelButtonTitle)
  • camera(function callback)
  • choose(string title, stringlist items, function callback, bool cancelable)
  • confirm(string title, string description, function callback, bool allowCancel)
  • inputText(string title, string description, string placeholder, string text, function callback)
  • pickDate(function callback, date initialDate, date minDate, date maxDate)
  • pickFile(function callback, string title, string path, string filter, string selectedFilter, bool selectMultiple)
  • pickImage(function callback, string title)

Detailed Description

NativeDialog allows to invoke native system dialogs and may be used to confirm a user action or to request a text input from the user. NativeDialog is a global object, and can be used without creating additional QML objects.

As an alternative to invoking a native dialog, InputDialog may be used to show a QML based dialog. It also supports multi-line text input. If you want to show a dialog with custom content, use the Dialog component.

Confirm Dialog

The confirm dialog has a title and can display a message. The dialog can be canceled or accepted:

 AppButton {
   id: confirmBtn
   text: "Confirm Dialog"
   onClicked: NativeDialog.confirm("Please Confirm", "Confirm this action?", function(ok) {
     if(ok) {
       confirmBtn.text = "Confirmed!"
     }
   })
 }

Input Dialog

The input dialog allows to enter text and may either be cancelled or accepted:

 AppButton {
   id: inputBtn
   text: "Input Dialog"
   onClicked: {
     NativeDialog.inputText("Quick Question", "What do you think?", "Input here", "", function(ok, text) {
       if(ok) {
         inputBtn.text = "Input: " + text
       }
     })
   }
 }

Method Documentation

[since Felgo 4.2.0] alert(string title, string description, function callback, string okButtonTitle, string cancelButtonTitle)

Displays a native alert dialog with a given title and description. It includes an OK button and an optional Cancel button that can also be localized.

The callback function will be called when one of the buttons is clicked. It receives a bool value as the parameter, which is set to true if the user chose to accept.

This method was introduced in Felgo 4.2.0.


[since Felgo 4.2.0] camera(function callback)

Allows to take a photo by starting the native camera, if available. It copies the new photo to the app's private storage folder.

The callback function will be called when the created photo is submitted. It receives a bool value as the first and a string as the second parameter. The first parameter is set to true if the user selected an image. The second parameter holds the path to the selected image or an empty string if canceled.

This method was introduced in Felgo 4.2.0.


[since Felgo 4.2.0] choose(string title, stringlist items, function callback, bool cancelable)

Displays a modal alert sheet with the specific options. It uses an AlertDialog on Android and a UIActionSheet on iOS.

The native dialog shows the title and offers the specified items as options. The parameter cancelable decides whether the user can cancel the dialog or is forced to choose an option. The default behavior allows to cancel.

The callback function will be called when one of the items is clicked. It receives an int value as the parameter, which holds the selected option or -1 if canceled.

This method was introduced in Felgo 4.2.0.


confirm(string title, string description, function callback, bool allowCancel)

Invokes the native confirm dialog with two buttons to cancel or accept. The optional allowCancel parameter is true by default and may be used to display a dialog with no cancel option.

The callback function will be called when one of the buttons is clicked. It receives a bool value as a parameter. It is set to true if the user chose to accept.


inputText(string title, string description, string placeholder, string text, function callback)

Invokes a native input dialog that holds a text field and two buttons to cancel or accept. The text and placeholder parameter set the initial text of the input field and the placeholder text if it is empty.

The callback function will be called when one of the buttons is clicked. It receives a bool value as the first and a string as the second parameter. The first parameter is set to true if the user chose to accept. The second parameter holds the entered text.


[since Felgo 4.2.0] pickDate(function callback, date initialDate, date minDate, date maxDate)

Allows to choose a date from a calendar by displaying a native date picker dialog, if available.

The parameters allow detailed control over the selectable dates. The initialDate parameter specifies the date selected when the date picker is opened. The minDate and the maxDate parameters specify the range of selectable dates. It is also possible to omit all three parameters, or to only specify the initialDate.

The callback function will be called when one of the buttons is clicked. It receives a bool value as the first and a date as the second parameter. The first parameter is set to true if the user pressed the OK button after selecting a date. The second parameter holds the year, month and day of month of the selected date.

This method was introduced in Felgo 4.2.0.


[since Felgo 4.2.0] pickFile(function callback, string title, string path, string filter, string selectedFilter, bool selectMultiple)

Displays a native file picker control. Different features are supported depending on the platform. The parameters are optional and match the QFileDialog::getOpenFileName capabilities:

  • title - Caption text of the dialog.
  • path - Base path for the file picker.
  • filter - Adds filter options for certain file types.
  • selectedFilter - The initially selected filter option.
  • selectMultiple - If multiple files can be selected.

The callback function will be called when one of the buttons is clicked on the file picker. It receives a bool value as the first and a var as the second parameter. The first parameter is set to true if the user selected one or more files. The second parameter holds a list of the file paths.

This method was introduced in Felgo 4.2.0.


[since Felgo 4.2.0] pickImage(function callback, string title)

Displays a native image picker control. Allows to choose a photo from the device by displaying the native image picker, if available. It copies the chosen photo to the app's private storage folder.

The callback function will be called when one of the buttons is clicked on the image picker. It receives a bool value as the first and a string as the second parameter. The first parameter is set to true if the user selected an image. The second parameter holds the path to the selected image or an empty string if canceled.

This method was introduced in Felgo 4.2.0.


Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded