I think I could have been more clear.
We are building a desktop app, and want it to be keyboard friendly.
So, in an alert with a text input, want to have the ENTER key event in that input act as “OK”.
Along the way, also noticed I needed to jump through hoops to set the focus to the input field as well;
Here is what I came up with.
opts.inputs[0].id = this.inputID;
return this.alertCtrl.create(opts)
.then((a) => {
if (this.inputID) {
const elem = this.document.getElementById(this.inputID);
if (elem) {
// hack to set focus on the <input>
setTimeout(() => { elem.focus(); }, 100);
elem.onkeyup = (ev) => {
if (ev.key === 'Enter') {
doSomeAction();
return this.alertCtrl.dismiss();
}
};
}
}
return a.present();
Thank you for sharing your response, it really helped me!
It’s a shame Ionic misses these basic concepts/functionalities like a “confirm” role.
I’ve came across several nuisance like this, for basic stuff, that I had to patch an ugly javascript hack to do the job.