Using Ionic 3, I have created a prompt alert that is triggered by a function resetPassword(). I want its only input to be focused and open the iOS / Android keyboard when displayed.
This is the function:
resetPassword() {
let prompt = this.alertCtrl.create({
title: 'Reset Password',
message: "Enter your email address to receive a password reset email",
inputs: [
{
name: 'email',
placeholder: 'Email',
type: 'email'
},
],
buttons: [
{
text: 'Cancel',
handler: data => {
console.log('Cancel clicked', data);
}
},
{
text: 'Send',
handler: data => {
console.log('Send clicked');
}
}
]
});
prompt.present().then(() => {
console.log("presenting")
const firstInput: any = document.querySelector('ion-alert input');
console.log("alert input", JSON.stringify(firstInput))
firstInput.focus();
return;
});
}
Using .focus() seems to not be working.
Logging JSON.stringify(firstInput) displays the following on iOS:
{
"__zone_symbol__ngModelChangefalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:ngModelChange",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__inputfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:input",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__blurfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:blur",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__compositionstartfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:compositionstart",
"zone": "angular",
"runCount": 0
}],
"__zone_symbol__compositionendfalse": [{
"type": "eventTask",
"state": "scheduled",
"source": "HTMLInputElement.addEventListener:compositionend",
"zone": "angular",
"runCount": 0
}]
}
What can I do to fix this?