Git Product home page Git Product logo

cordova-plugin-dialogs's Introduction

title description
Dialogs
Use native dialog UI elements

cordova-plugin-dialogs

Android Testsuite Chrome Testsuite iOS Testsuite Lint Test

This plugin provides access to some native dialog UI elements via a global navigator.notification object.

Although the object is attached to the global scoped navigator, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.notification);
}

Installation

cordova plugin add cordova-plugin-dialogs

Methods

  • navigator.notification.alert
  • navigator.notification.confirm
  • navigator.notification.prompt
  • navigator.notification.beep
  • navigator.notification.dismissPrevious
  • navigator.notification.dismissAll

navigator.notification.alert

Shows a custom alert or dialog box. Most Cordova implementations use a native dialog box for this feature, but some platforms use the browser's alert function, which is typically less customizable.

navigator.notification.alert(message, alertCallback, [title], [buttonName])
  • message: Dialog message. (String)

  • alertCallback: Callback to invoke when alert dialog is dismissed. (Function)

  • title: Dialog title. (String) (Optional, defaults to Alert)

  • buttonName: Button name. (String) (Optional, defaults to OK)

Example

function alertDismissed() {
    // do something
}

navigator.notification.alert(
    'You are the winner!',  // message
    alertDismissed,         // callback
    'Game Over',            // title
    'Done'                  // buttonName
);

Supported Platforms

  • Android
  • Browser
  • iOS
  • Windows

navigator.notification.confirm

Displays a customizable confirmation dialog box.

navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
  • message: Dialog message. (String)

  • confirmCallback: Callback to invoke with index of button pressed (1, 2, or 3) or when the dialog is dismissed without a button press (0). (Function)

  • title: Dialog title. (String) (Optional, defaults to Confirm)

  • buttonLabels: Array of strings specifying button labels. (Array) (Optional, defaults to [OK,Cancel])

confirmCallback

The confirmCallback executes when the user presses one of the buttons in the confirmation dialog box.

The callback takes the argument buttonIndex (Number), which is the index of the pressed button. Note that the index uses one-based indexing, so the value is 1, 2, 3, etc.

Example

function onConfirm(buttonIndex) {
    alert('You selected button ' + buttonIndex);
}

navigator.notification.confirm(
    'You are the winner!', // message
     onConfirm,            // callback to invoke with index of button pressed
    'Game Over',           // title
    ['Restart','Exit']     // buttonLabels
);

Supported Platforms

  • Android
  • Browser
  • iOS
  • Windows

Android Quirks

  • Android supports a maximum of three buttons, and ignores any more than that.

  • Android dialog title cannot exceed 2 lines of content, it will ignore any more than this.

Windows Quirks

  • On Windows8/8.1 it is not possible to add more than three buttons to MessageDialog instance.

  • On Windows Phone 8.1 it's not possible to show dialog with more than two buttons.

navigator.notification.prompt

Displays a native dialog box that is more customizable than the browser's prompt function.

navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText])
  • message: Dialog message. (String)

  • promptCallback: Callback to invoke with index of button pressed (1, 2, or 3) or when the dialog is dismissed without a button press (0). (Function)

  • title: Dialog title (String) (Optional, defaults to Prompt)

  • buttonLabels: Array of strings specifying button labels (Array) (Optional, defaults to ["OK","Cancel"])

  • defaultText: Default textbox input value (String) (Optional, Default: empty string)

promptCallback

The promptCallback executes when the user presses one of the buttons in the prompt dialog box. The results object passed to the callback contains the following properties:

  • buttonIndex: The index of the pressed button. (Number) Note that the index uses one-based indexing, so the value is 1, 2, 3, etc.

  • input1: The text entered in the prompt dialog box. (String)

Example

function onPrompt(results) {
    alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
}

navigator.notification.prompt(
    'Please enter your name',  // message
    onPrompt,                  // callback to invoke
    'Registration',            // title
    ['Ok','Exit'],             // buttonLabels
    'Jane Doe'                 // defaultText
);

Supported Platforms

  • Android
  • Browser
  • iOS
  • Windows

Android Quirks

  • Android supports a maximum of three buttons, and ignores any more than that.

  • On Android 3.0 and later, buttons are displayed in reverse order for devices that use the Holo theme.

Windows Quirks

  • On Windows prompt dialog is html-based due to lack of such native api.

navigator.notification.beep

The device plays a beep sound.

navigator.notification.beep(times);
  • times: The number of times to repeat the beep. (Number)

Example

// Beep twice!
navigator.notification.beep(2);

Supported Platforms

  • Android
  • Browser
  • iOS
  • Windows 8

Android Quirks

  • Android plays the default Notification ringtone specified under the Settings/Sound & Display panel.

navigator.notification.dismissPrevious

Dismisses the previously opened dialog box. If no dialog box is currently open, the errorCallback will be called.

navigator.notification.dismissPrevious([successCallback], [errorCallback])
  • successCallback: Callback to invoke when previously opened dialog has been dismissed. (Function) (Optional)
  • errorCallback: Callback to invoke on failure to dismiss previously opened dialog. Will be passed the error message. (Function) (Optional)

Example

function successCallback() {
    console.log("Successfully dismissed previously opened dialog.");
}

function errorCallback(error) {
    console.log("Failed to dismiss previously opened dialog: " + error);
}

navigator.notification.dismissPrevious(
    successCallback,
    errorCallback
);

Supported Platforms

  • Android
  • iOS

navigator.notification.dismissAll

Dismisses all previously opened dialog boxes. If no dialog box is currently open, the errorCallback will be called.

navigator.notification.dismissAll([successCallback], [errorCallback])
  • successCallback: Callback to invoke when all previously opened dialogs have been dismissed. (Function) (Optional)
  • errorCallback: Callback to invoke on failure to dismiss all previously opened dialogs. Will be passed the error message. (Function) (Optional)

Example

function successCallback() {
    console.log("Successfully dismissed all previously opened dialogs.");
}

function errorCallback(error) {
    console.log("Failed to dismiss all previously opened dialogs: " + error);
}

navigator.notification.dismissAll(
    successCallback,
    errorCallback
);

Supported Platforms

  • Android
  • iOS

cordova-plugin-dialogs's People

Contributors

agrieve avatar alsorokin avatar bennmapes avatar cfjedimaster avatar clelland avatar cmarcelk avatar dblotsky avatar dpa99c avatar erisu avatar filmaj avatar hardeep avatar hazems avatar janpio avatar jcesarmobile avatar ldeluca avatar macdonst avatar matrosov-nikita avatar mbillau avatar mwoghiren avatar nikhilkh avatar niklasmerz avatar purplecabbage avatar sgrebnov avatar shazron avatar stacic avatar stevengill avatar timbru31 avatar vladimir-kotikov avatar zalun avatar zaspire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-dialogs's Issues

After removing and re-adding plugin, DeviceReady won't fire

I'm developing an app on iOS.
I have removed the 2.0.2 version of the plugin then re-installed it from this repo. The app didn't start, the DeviceReady event never fired. Then I've removed the plugin and added v2.0.2 again but the same problem persists.
The problem exists on any real iOS device and also in the simulator. PLEASE HELP!!!! :-/

Race condition with activityStart/activityStop can leave dialog on screen [Android]

Bug Report

Problem

There is a potential race condition problem in activityStart/activityStop, because the former shows the spinner dialog in the UI thread, while the latter hides the spinner dialog in the JS thread. So it is possible for activityStop to try to hide the spinner dialog, while it hasn't event been shown yet, if activityStop is executed immediately (or shortly) after activityStart.

For instance, using the following code (e.g. in Chrome remote debugging console):

navigator.notification.activityStart('', 'Wait...'); navigator.notification.activityStop()

What is expected to happen?

activityStop should always discard a spinner dialog initiated by activityStart.

What does actually happen?

activityStop has no effect, because the spinner dialog hasn't been created yet by activityStart (due to execution in UI thread).

Environment, Platform, Device

Android

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Prompt dialog won't focus nor show keyboard on Android until manually tapping the text input.

Bug Report

Problem

On Android, prompt dialog won't focus and show keyboard until manually tapping the text input.

What is expected to happen?

Automatically show keyboard when calling navigator.notification.prompt.

What does actually happen?

The prompt view is shown, but without any focus on the input field and without displaying the keyboard.

Information

There's a PR addressing the issue #132 , but still it doesn't focus in my tests.

Command or Code

navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText])

Environment, Platform, Device

Tested on Android devices running 7.1.1 (Moto G Play) & 9.0 (ZTE Blade V10 VIta).

Version information

  • Cordova CLI v9.0.0 ([email protected]).
  • Android v8.1.0
  • cordova-plugin-dialogs v2.0.2
  • MacOS v10.15.5

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

This plugin makes Cordova app device ready not firing

Bug Report

Problem

cordova-plugin-dialogs breaks Cordova. Never fires deviceready.
Tested with an empty repo. Added a few plugins.

<plugin name="cordova-plugin-device" spec="^2.1.0" />
<plugin name="cordova-plugin-network-information" spec="^3.0.0" />
<plugin name="cordova-plugin-statusbar" spec="^3.0.0" />

Everything works fine, deviceready is fired. Then adding

<plugin name="cordova-plugin-dialogs" spec="^2.0.2" />

Breaks the app, deviceready never fired

Environment, Platform, Device

Reproduced on device Android 6.0.1

Version information

Cordova 11.0.0
cordova-android 10.1.2

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Wy isn't feature (GH-128), aka dialog dismissal, included in latest release

Issue Type

  • Bug Report
  • Feature Request
  • Support Question

Description

This change is almost 2 years old and is only on the master branch. Any chance it is getting added to a release anytime soon?

  • I searched for already existing GitHub issues about this
  • I updated all Cordova tooling to their most recent version
  • I included all the necessary information above

UIAlertView is deprecated

UIAlertView' is deprecated

Problem

UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

What does actually happen?

I recently installed Cordova 10
I am building a Android and IOS App with Cordova. From Xcode, when I run my App I have several warning
UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

As I am novice, it's a bit hrad for me to adapt the plugin. There is a updated version or someone could help me solve it?
I am only using the plugin for the bip method. May be there is another way to bip the smartphone?

Thank for the support

Environment, Platform, Device

jQuery, Cordova 10, Xcode 12, OSX10.15

Don't specify light theme on Android

The dialogs plugin on Android has the light theme hardcoded. I think the plugin shouldn't try to guess what's best, and let the app and/or the platform decide the theme the apply (usually based on the default device theme and the target SDK of the app). Is there a good reason for the dialogs plugin to assume that using the light theme unconditionally is the right way to go?

All audio comes out of the earpiece instead when notifications are used

Bug Report

Problem

When I use javascript code from this package, all the audio including music in the WKWebView outputs audio through the earpiece. The volume is really low. I tried setting all audio to come out of the main speaker using this audio plugin, but the notification beeps no longer are outputted.

https://github.com/neohelden/cordova-plugin-audiotoggle

What is expected to happen?

Notification beeps come out from the speaker.

What does actually happen?

Low volume sounds and audio coming out from the earpiece.

Information

Using latest release

Command or Code

navigator.notification.beep(2);

Environment, Platform, Device

iOS 13.7 WKWebView

Version information

What are relevant versions you are using?
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins: 10.0.0 , iOS platform 6.1.1
Other Frameworks: Ionic Framework and CLI version: No Framework

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

'UIAlertView' is deprecated when installing cordova-plugin-dialogs

Hi!

I'm having issues installing Cordova-plugin-dialogs to use for my project.
This plugin: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-dialogs/index.html
Installing works fine without issues but when I build it, I get 7 fault codes all related to the 'UIAlertView' is deprecated.
I do not know how to fix this even though this has been replaced dby some UIAlertController?

Skärmavbild 2022-05-18 kl  23 57 41

I have checked a tons of tickets regarding this, removed my ios platforms, started a new project fresh from start etc etc etc.
I really have no clue of how to fix this issue.

Please help me

notification.alert not working on cordova run browser

Bug Report

notification.alert

Problem

not working on cordova run browser

What is expected to happen?

What does actually happen?

Notification Alert Does Not Work When Running in Cordova Run Browser

Information

Command or Code

navigator.notification.alert("Maaf Promo tidak di temukan",null,'Informasi',['Ok']);

Environment, Platform, Device

Cordova Packages:

cli: 11.0.0
    common: 4.1.0
    create: 4.1.0
    lib: 11.1.0
        common: 4.1.0
        fetch: 3.1.0
        serve: 4.0.1

Project Installed Platforms:

android: 12.0.0
browser: 7.0.0

Project Installed Plugins:

cordova-plugin-app-version: 0.1.9
cordova-plugin-browsersync-gen2: 1.1.7
cordova-plugin-camera: 6.0.1-dev
cordova-plugin-device: 2.0.3
cordova-plugin-dialogs: 2.0.2
cordova-plugin-file: 6.0.2
cordova-plugin-firebasex: 16.1.0
cordova-plugin-geolocation: 4.0.2
cordova-plugin-minify: 0.1.2
cordova-plugin-network-information: 2.0.2
cordova-plugin-statusbar: 2.4.3
cordova-plugin-vibration: 3.1.1
cordova-plugin-x-socialsharing: 6.0.4
es6-promise-plugin: 4.2.2
phonegap-plugin-barcodescanner: 8.1.1-dev

Environment:

OS: Microsoft Windows 10 Pro 10.0.19045 (19045) (Windows 10.0.19045) x64
Node: v18.17.1
npm: 9.6.7

android Environment:

android:

ERROR: Command failed with exit code 1: avdmanager list target
'avdmanager' is not recognized as an internal or external command,
operable program or batch file.

Project Setting Files:

config.xml:
App.com -. IT Technologi need camera access to take pictures need photo library access to get pictures from there need location access to find things nearby need photo library access to save pictures there
package.json:

--- Start of Cordova JSON Snippet ---
{
"plugins": {
"cordova-plugin-app-version": {},
"cordova-plugin-device": {},
"cordova-plugin-dialogs": {},
"cordova-plugin-network-information": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-vibration": {},
"phonegap-plugin-barcodescanner": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
},
"cordova-plugin-geolocation": {
"GPS_REQUIRED": "false"
},
"cordova-plugin-file": {},
"cordova-plugin-x-socialsharing": {},
"cordova-plugin-firebasex": {
"FIREBASE_ANALYTICS_COLLECTION_ENABLED": "true",
"FIREBASE_PERFORMANCE_COLLECTION_ENABLED": "true",
"FIREBASE_CRASHLYTICS_COLLECTION_ENABLED": "true",
"FIREBASE_FCM_AUTOINIT_ENABLED": "true",
"ANDROID_ICON_ACCENT": "#FF00FFFF",
"ANDROID_FIREBASE_PERFORMANCE_MONITORING": "false",
"ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION": "18.0.2",
"ANDROID_PLAY_SERVICES_AUTH_VERSION": "20.5.0",
"ANDROID_FIREBASE_ANALYTICS_VERSION": "21.2.2",
"ANDROID_FIREBASE_MESSAGING_VERSION": "23.1.2",
"ANDROID_FIREBASE_CONFIG_VERSION": "21.4.0",
"ANDROID_FIREBASE_PERF_VERSION": "20.3.2",
"ANDROID_FIREBASE_AUTH_VERSION": "22.0.0",
"ANDROID_FIREBASE_INAPPMESSAGING_VERSION": "20.3.2",
"ANDROID_FIREBASE_FIRESTORE_VERSION": "24.6.0",
"ANDROID_FIREBASE_FUNCTIONS_VERSION": "20.3.0",
"ANDROID_FIREBASE_IID_VERSION": "21.1.0",
"ANDROID_FIREBASE_INSTALLATIONS_VERSION": "17.1.3",
"ANDROID_FIREBASE_CRASHLYTICS_VERSION": "18.3.7",
"ANDROID_FIREBASE_CRASHLYTICS_NDK_VERSION": "18.3.7",
"ANDROID_GSON_VERSION": "2.9.0",
"ANDROID_FIREBASE_PERF_GRADLE_PLUGIN_VERSION": "1.4.2",
"ANDROID_GRPC_OKHTTP": "1.46.0"
},
"cordova-plugin-minify": {},
"cordova-plugin-browsersync-gen2": {},
"cordova-plugin-camera": {
"ANDROIDX_CORE_VERSION": "1.6.+"
}
},
"platforms": [
"browser",
"android"
]
}
--- End of Cordova JSON Snippet ---

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Title is cut off for long titles on android

I have a function that is using the plugin as follows:

navigator.notification.alert(
      message, // message
      () => {}, // callback
      header, // title
      'Ok' // buttonName
    )

This works fine on iOS, however on Android when the header is big it doesn't split the text in new lines and shows '...' instead, I tried manually adding '\n' in the string, but its still showing ... instead of the full header message.

Dialog buttons alignment is broken

Bug Report

Problem

The dialog button is aligned in the dialog box for android. One button on right and another on left.
Bug Screenshot:

Does this plugin following material design guidelines?

What is expected to happen?

  • Expected the button should have next to each other.

Environment, Platform, Device

App Version Screen Resolution Installed from Android Version Device
v1.3.1 360*640 Locally 7.1.0 Nokia-6

Version information

Cordova: Cordova Plugins
Other Frameworks: Android Studio

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to a most recent version
  • I included all the necessary information above

Prompt don't close until callback?

Is there a way with the prompt() method to not close it until a function completes?

For example, I'm using the following to prompt a user for their password to confirm account changes, upon successful password it should just show an alert but if the password is incorrect it should leave the prompt open for them to attempt it again.

this.dialogs.prompt(
      'Enter your password please', 
      'Password',
      [
        'Close',
        'OK'
      ]
    )

It seems that no matter what, the buttons always close the prompt, they have no option to leave it open.

Alert notification does not working

I installed via: (Windows 10)
cordova plugin add cordova-plugin-dialogs

And when I use navigator.notification.alert() function, my code does not work, if I use only alert() (without navigator.notification) shows the classic alert but it works properly

Can You help me?
Thanks.

And I have this code:

// Javascript
function onDeviceReady() {
navigator.notification.alert("Message", null, "Title", 'Ok');
btnAppRegister = document.getElementById("btnAppRegister");
btnAppRegister.addEventListener("click", function() {
accessWebService();
});
}

Configure access


	<div class="ui-field-contain">
		<label for="txtAppUser">User:</label>
		<input type="text" name="txtAppUser" id="txtAppUser" />
	</div>
	
	<div class="ui-field-contain">
		<label for="txtAppPass">Password:</label>
		<input type="password" name="txtAppPass" id="txtAppPass" />
	</div>
	
	<input type="button" id="btnAppRegister" value="Registrar" />
	
</div>

navigator.notification.prompt "longer" text on ios

Hello!

When I enter a long text to the prompt dialog the ios doesn't wrap into multiple lines and I can't see the whole message.
Android is works well.

iphone

Is there any way to wrap the text on ios?

Thanks in advance!

RTL Support

Feature Request

RTL Support.

Motivation Behind Feature

This plugin is amazing and easy to use. the only thing that should be added to the plugin is RTL support.

Feature Description

Alternatives or Workarounds

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.