Grisza Grisza - 7 months ago 8
Javascript Question

How does it work the argument buttonIndex in cordova-plugin-dialogs?

Hi I have problem with setting

if (buttonIndex == 1) {
//do stuff
} else if (buttonIndex == 2) {
//II do stuff
}


so is the app knows about buttonIndex in
if
? Whether it knows only in
function onConfirm(buttonIndex){}

about buttonIndex?
Generally is it about confirm dialog https://www.npmjs.com/package/cordova-plugin-dialogs#navigatornotificationconfirm this dialog works but only display info
when clicked 'Tak' so buttonIndex == 1 (Tak is in English Yes) then I want to append
<li>
with name chipsy(in English chips) and a button to
<ul>
this doesn't work
here is my code http://pastebin.com/Wf7untcY

It is an issue with appending or with buttonIndex?

Answer

solved it was an issue with wrong sequence of function 'content'

The right order

function onConfirm(buttonIndex) {
                                if (buttonIndex == 1) {

                                    var li = $('<li/>');
                                    var lv = $('#lv');
                                    var divP = $('<div/>', {
                                                'class':"ui-grid-a"}).appendTo(li);
                                    var divC1 = $('<div/>', {
                                                 'class':"ui-block-a",
                                                 text:'chips'}).appendTo(divP);
                                    var btnDel = $('<button/>', {
                                                 'class':"ui-btn ui-icon-delete ui-btn-icon-notext ui-btn-inline",
                                                 click: function() {
                                                    li.empty();
                                                 }
                                    });

                                    var divC2 = $('<div/>', {
                                                'class':"ui-block-b"}).appendTo(divP).append(btnDel);

                                    lv.append(li);

                                    window.plugins.toast.showLongBottom('Added chips to shopping list');
                                } else if (buttonIndex == 2) {
                                    window.plugins.toast.showLongBottom('Not added');
                                }
                            }

                            navigator.notification.confirm('Do you want to add chips to beer?', onConfirm, 'Basket Analysis', ['Yes','No']);
Comments