Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Tobster_
Posts: 270
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C

Creating a dialog box

[ Edited ]

I have been searching all across the forums and the internet but I could not find a solution on how to do this. 

 

What I am looking to do is to create a dialog box that has the two options: confirm and cancel. 

 

When the confirm option is selected, the options that have been selected get deleted and my toast message appears and when the cancel option is selected, the options that have been selected do not get deleted and my other toast message appears. 

 

Here is the code I have currently put together: 

 

            DeleteActionItem {
                ActionBar.placement: ActionBarPlacement.OnBar
                imageSource: "asset:///IMG/ic_delete.png"
                title: qsTr("Delete") + Retranslate.onLanguageChanged
                onTriggered: {
                    deleteDialog.show();
                    // Delete the selected items. 
                    var selectionList = bucketList.selectionList();
                    bucketList.clearSelection();
                    bucketModel.deleteBucketItems(selectionList);
                }
                attachedObjects: [
                    SystemToast {
                        id: deleteToast
                        body: qsTr("Items have been deleted.")
                    },
                    SystemToast {
                        id: deleteToastCancelled
                        body: qsTr("Cancelled")
                    },
                    SystemDialog {
                        id: deleteDialog
                        title: qsTr("Delete?")
                        body: qsTr("Are you sure you want to delete? :)")
                        emoticonsEnabled: true
                        
                        onFinished: {
                            if (deleteDialog != SystemUiResult.CancelButtonSelection) {
                                //user didn't cancel
                                deleteToast.show();
                            }
                        }
                    }
                ]
            
            }

 I am working off of the bucket list sample found here.

 

In another section of my app, I am using toasts and system dialogs and they work perfectly:

 

DeleteActionItem {
            ActionBar.placement: ActionBarPlacement.OnBar
            imageSource: "asset:///IMG/ic_delete.png"
            title: qsTr("Delete") + Retranslate.onLanguageChanged
            onTriggered: {
                deletenoteDialog.show();
            }
            attachedObjects: [
                SystemToast {
                    id: deletenoteToast
                    body: qsTr("Your note has been deleted.")
                },
                SystemToast {
                    id: deletenoteToastCancelled
                    body: qsTr("Cancelled")
                },
                SystemDialog {
                    id: deletenoteDialog
                    title: qsTr("Delete?")
                    body: qsTr("Are you sure you want to delete? :)")
                    emoticonsEnabled: true
                    
                    onFinished: {
                        if (deletenoteDialog.result == 3) {
                            deletenoteToastCancelled.show();
                            return;
                        } else {
                            _noteBook.deleteNote()
                            navigationPane.pop()
                            deletenoteToast.show();
                        }
                    }
                }
            ]
        
        }

 I have tried to make the first snippet of code like that too but as soon as I move 

var selectionList = bucketList.selectionList();
                    bucketList.clearSelection();
                    bucketModel.deleteBucketItems(selectionList);

into the onFinished event, the items delete regardless of whether the user has press OK or cancel. 

 

Any help with getting this to work would be fantastic!

 

Thanks in advance :smileyhappy: 

Developer
soaman
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Creating a dialog box

You put:

if (deleteDialog != SystemUiResult.CancelButtonSelection)

 

But you should check the result of the dialog!!!! 

--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Developer
Tobster_
Posts: 270
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C

Re: Creating a dialog box

Hi soaman, 

 

Thanks for replying. 

 

I changed a few things around and my code currently looks like this:

 

            DeleteActionItem {
                ActionBar.placement: ActionBarPlacement.OnBar
                imageSource: "asset:///IMG/ic_delete.png"
                title: qsTr("Delete") + Retranslate.onLanguageChanged
                onTriggered: {
                    deleteDialog.show();
                    // Delete the selected items. Clear selection before items are manipulated to avoid blink.
                    var selectionList = bucketList.selectionList();
                    bucketList.clearSelection();
                    bucketModel.deleteBucketItems(selectionList);
                }
                attachedObjects: [
                    SystemToast {
                        id: deleteToast
                        body: qsTr("Items have been deleted.")
                    },
                    SystemToast {
                        id: deleteToastCancelled
                        body: qsTr("Cancelled")
                    },
                    SystemDialog {
                        id: deleteDialog
                        title: qsTr("Delete?")
                        body: qsTr("Are you sure you want to delete? :)")
                        emoticonsEnabled: true

                        onFinished: {
                            if (deleteDialog.result == 3) {
                                deleteToastCancelled.show();
                                return;
                            } else {
                                deleteToast.show();
                            }
                        }
                    }
                ]

            }

 The toasts fire correctly, if I click OK then the deleteToast shows and if I click cancel the deleteToastCancelled shows but even before I click either of the buttons, the items get deleted anyway so I'm not sure what I am doing wrong.

Developer
soaman
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Creating a dialog box

Of course, move:

var selectionList = bucketList.selectionList();
                    bucketList.clearSelection();
                    bucketModel.deleteBucketItems(selectionList);

 

into deleteToast section - it has its own onFinished slot.

 

 

--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Developer
Tobster_
Posts: 270
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C

Re: Creating a dialog box

Thanks for the tip but I tried moving it into the deleteToast's onFinished() as well as moving it into the deleteDialog's onFinished() but putting that snippet of code in either of those areas causes the app to crash but I'm not sure why it does that
Developer
soaman
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Creating a dialog box

[ Edited ]

Unfortunately I need some free time to check that. (edited)

--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Developer
soaman
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

Re: Creating a dialog box

Without full code it is hard to figure it out.

 

What happens if you remove the middle line. If you delete selected items, clearing may be useless?

--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development