I have a Angular 4.3
application where i have a contenteditable
I need to validate input before it can be it can be reflected in UI (in this instance only numbers upto three charecters can be typed )
In desktop browsers this accomplished using (keydown)
event and returning false
on invalid input
But in mobile browser(Android Chrome) both keydown
and keypress
events are not triggered consistently, instead input
Event is fired.
but using InputEvent
i cannot prevent modifying data on invalid input
Example HTML template
<p contenteditable=true (keydown)="onKeyDown($event)" (input)="onInput($event)"></p>
and component code is
public onKeyDown($event:KeyboardEvent){ // works
if(invalidInput){
return false;
}
return true;
}
public onInput($event:InputEvent){ // does'nt works
if(invalidInput){
$event.preventDefault();
return false;
}
return true;
}
PS: Is there a way to trigger numberpad keyboard for input with contenteditable
and and it would be easier. If you are interested, I could post a snippet
– Vega Sep 07 '17 at 05:47