I'm trying to use the Phonegap notification to display an error message in my Phonegap app, and then allow the user to email the error. The only problem is I can't pass the error message to the callback function, rendering the email useless.
The code I have now looks like this:
function displayError(errormsg) {
navigator.notification.confirm(
errormsg,
onConfirm,
'Error',
'Submit, Cancel'
);
}
function onConfirm(buttonIndex){
if (buttonIndex === 1){
alert(errormsg);
}
}
Which is called by displayError("Test")
, which would make the error content Test
. I want to then pass errormsg
on to onConfirm
, but I don't know how to do this, or if it's possible.
A possible solution I was considering was this:
function displayError(errormsg) {
test = errormsg
navigator.notification.confirm(
errormsg,
onConfirm,
'Error',
'Submit, Cancel'
);
}
function onConfirm(buttonIndex){
if (buttonIndex === 1){
alert(test);
}
}
But that doesn't change the errormsg
if a new error is displayed. I confirmed this because in the simulator setting, my app throws two errors. The first one works fine when using that method, passing on test
, but then the second error which directly follows uses the original variable, instead of the most recent one.
function displayError(errormsg) {
navigator.notification.confirm(
errormsg,
function(buttonIndex){
onConfirm(buttonIndex, errormsg);
},
'Error',
'Submit, Cancel'
);
}
function onConfirm(buttonIndex, errormsg){
if (buttonIndex === 1){
alert(errormsg);
}
}
What about wrapping it in an anonymous function? That way you can pass as many parameters as you like, while maintaining scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With