0

So, i just want remove when we delete data from input fields when we try to clear the input field then it's not going to clear because of i have added hyphen dynamically so is there a way to delete the or clear the input fields.

Basically i have added hyphen in the input field, but i am not able to delete hyphen when i trye to clear or deleting the data. please somebody help me out.

Here is my running code

mp3
  • 3
  • 1
  • Duplicate?: https://stackoverflow.com/questions/50905432/automatic-hyphens-while-typing-date-in-input-type-date-angular-5 – Krishna Mohan Sep 27 '20 at 18:46

1 Answers1

0

You are already half way done all you need to:

Replace

if(event.keyCode === 8 || event.key === "Delete") return;

With

if(!event.data) return;
Kamran Khatti
  • 3,754
  • 1
  • 20
  • 31
  • Yes i tried out but it's kind of stuck after removing hyphen. i didn't get it how can i delete or clear the input filed. – mp3 Sep 27 '20 at 18:48
  • @mp3 why it stuck I have tried your example and it works fine. – Kamran Khatti Sep 27 '20 at 18:50
  • Yes, now it's working fine thank you so much. :-) i did spelling mistake – mp3 Sep 27 '20 at 18:58
  • @mp3 perfect, you can accept and upvote the answer it will help other colleagues. – Kamran Khatti Sep 27 '20 at 19:00
  • one more thing it's just user experience when user enter invalid **Day** like 45 then user should not able to type anything until he enter right day – mp3 Sep 27 '20 at 19:01
  • Its bcz the logic you added behaves like this, you could refactor `if` condition part in your `addHyphen` method. – Kamran Khatti Sep 27 '20 at 19:05
  • And i forget to mentioned that mine angular project works on mobile webview and mobile webview doesn't support **(keydown)** so is there a way deal with **(input)** only . so if you want to reproduce the error you can open above code preview in mobile. – mp3 Sep 27 '20 at 19:11
  • @mp3 I have updated my answer now you can use `input` with slight change in your `if` condition, try it out. – Kamran Khatti Sep 27 '20 at 19:46
  • wow, nice thank you so much. i am really appreciate brother. thanks a lot. – mp3 Sep 27 '20 at 19:49
  • @mp3 glad to help you :) – Kamran Khatti Sep 27 '20 at 19:50