Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Showing confirm dialog box using cordova-plugin-dialogs

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.72k
    Comment on it

    This plugin provides us some native dialog elements that are much more customizable than the browers dialogs.

    There are some methods in it:-

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

    First install the plugin: cordova plugin add org.apache.cordova.dialogs

    Then add the below script in your html.

    <script src="cordova.js"></script>
    

    It is only available after the deviceready event.

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

    Here I am showing an example of using navigator.notification.confirm :

    $scope.deletePhoto = function () {
                        navigator.notification.confirm(
                            'Are you sure you want to delete photo?',  // message
                        onConfirm, // callback
                            'Delete Photo, // title
            ['Restart','Exit']     // buttonLabels
    
                        );
                    };
    

    The callback takes the index of the button as its argument.

     function onConfirm( button ) {
            if( button == 1 ) {
                var deletePhotoData = {};
                deletePhotoData[ 'responsetype' ] = "json";
                console.log( JSON.stringify( deletePhotoData ) );
                var responsePromise = $http.post( BASE_URL+"removeprofilephoto",     JSON.stringify( deletePhotoData ) );
                responsePromise.success( function( data, status, headers, config ) {
                    console.log( JSON.stringify( data ) );
                    $( '#deleteBtn' ).html( data.message );
                    $( '#deleteBtn' ).addClass( 'errorStatus' );
                } );
                responsePromise.error( function ( data, status, headers, config ) {
                    console.log( JSON.stringify( data ) );
                    if( navigator.connection.type == Connection.NONE ) {
                        checkConnection();
                    }
                } );
            }
        }
    

    Below is the HTML from where the function will get called.

    <button type="button" class="delete btn btn-default fullwidth" ng-click="deletePhoto()">
                            Delete profile photo
                        </button>
    

    Inside this function you can apply any logic that you want to do on the click of OK button of the dialog box.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: