Ion-input keypress event.key un-valued on iOS 9

Hi,

I have a simple input and a method on the keypress event method, in which I want to print the char inserted.
All works with browser, with iOS simulator (ipad 10.3) and on devices (iphone / ipad 10.3).
But on iOS simulator/device with OS < 10, the event.key is empty. Only keyCode is valued.

I attach some code:

<ion-input  type="text" (keypress)="onKeyPressed($event)"></ion-input>
onKeyPressed(event){
    console.log(event.key) <---- not valued with iOS 9
    console.log(event.keyCode) <---- valued
    return true
}

Have you some suggestions to give me?
Thank you

1 Like

If you aren’t checking too many different keys, you could set up a map for the keys you’re checking and their .key and .keyCode values.

let map = {
	enter: {
		key: "enter",
		keyCode: "whatever"
	},
	...
};

if(event.key === map.enter.key || event.keyCode === map.enter.keyCode) {
	// Do stuff
}

Would that be an option? :slight_smile: