PinDialog
PinDialog copied to clipboard
Preventing the dialog from closing
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
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
}
};
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?.
hi @pliablepixels run out of stack space ? I don't know what the sentence true meaning if you mean "memory" ?
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.
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)
How do you do this using typescript?
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(); } } } );