PinDialog icon indicating copy to clipboard operation
PinDialog copied to clipboard

Preventing the dialog from closing

Open pliablepixels opened this issue 10 years ago • 7 comments
trafficstars

Hello, what is the best way to not close the dialog if the Pin is wrong? It doesn't pass an event handle so I can't call preventDefault

pliablepixels avatar Sep 14 '15 14:09 pliablepixels

hi @pliablepixels you can set

window.plugins.pinDialog.prompt("message", callback, "title", ["OK","Cancel"]);

function callback(results)
{
    if(results.buttonIndex == 1)
    {
     //suppose wrong value
     if(results.input1 == 'wrong')
     {
     window.plugins.pinDialog.prompt("message", callback, "title", ["OK","Cancel"]); //call again
     }

     //suppose right value
     if(results.input1 == 'right')
     {
     //do your magic
     }
    }
    if(results.buttonIndex == 2)
    {
    // Cancel clicked
    }
};

bau720123 avatar Sep 14 '15 14:09 bau720123

Hello, thanks! does this not keep adding to the function stack? If I keep entering wrong values, the callback function will keep calling itself and will (eventually) run out of stack space?.

pliablepixels avatar Sep 14 '15 14:09 pliablepixels

hi @pliablepixels run out of stack space ? I don't know what the sentence true meaning if you mean "memory" ?

bau720123 avatar Sep 14 '15 14:09 bau720123

Hello @bau720123 , yes - the code basically calls the callback function from within itself, so if you keep pressing OK repeatedly, the function stack will keep increasing and exhaust stack memory of the browser - which I would prefer to avoid. Thank you.

pliablepixels avatar Sep 15 '15 00:09 pliablepixels

hi @pliablepixels if you have "memory" issue how about made a "Counter" function for example 10 times

window.plugins.pinDialog.prompt("message", callback, "title", ["OK","Cancel"]);
var counter = 0;
function callback(results)
{
    if(results.buttonIndex == 1)
    {
     //suppose wrong value
     if(results.input1 == 'wrong')
     {
      if(counter <= 10)
      {
      window.plugins.pinDialog.prompt("message", callback, "title", ["OK","Cancel"]); //call again
      }
    counter += 1;
     }

     //suppose right value
     if(results.input1 == 'right')
     {
     //do your magic
     }
    }
    if(results.buttonIndex == 2)
    {
    // Cancel clicked
    }
};

I think that is just javascript callback function,it won't cause any memory issues (or maybe you can try how manys times will cause your memory issue)

bau720123 avatar Sep 15 '15 02:09 bau720123

How do you do this using typescript?

Jatapiaro avatar Sep 10 '17 07:09 Jatapiaro

I used this for typescript and works fine showPinDialog(){ return this.pinDialog.prompt('Enter your PIN', 'Verify PIN', ['OK', 'Cancel']) .then( (result: any) => { if (result.buttonIndex == 1){ if(this.validationService.validPinCode(result.input1)){ this.toTabs(); }else{ this.showPinDialog(); } } } );

Jatapiaro avatar Sep 10 '17 08:09 Jatapiaro