Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
How to disable typing but allow copy and paste in a text box in Angular 8?

I want to restrict typing in a text box but I need to paste anything inside that textbox in Angular

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to stop the event propagation if the combination pressed is different than the one you choose.

You can do it like this:

public onInput(event: KeyboardEvent) {
  //if is pressed a different key than c or v, or the ctrl key isn't pressed stop event
  if (!event.ctrlKey || (event.key.toLowerCase() !== 'c' && event.key.toLowerCase() !== 'v')) {
    event.stopImmediatePropagation();
    event.stopPropagation();
    event.preventDefault();
  } 

  // else execute the default event behaviour
}
<input type="text" (keydown)="onInput($event)">

Hope it helps. ^^

P.S.: You have to use the event keydown for this to work.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!