As I can tell it's not possible to just assign delete keycode to another key, so I tried to recreate its functionality, but I can't figure out how to do it properly.
I tried to do it with slice, and it actually does what it should for the first time, but then any key I press triggers delete.
window.addEventListener("keydown", function(e) {
let formuleInput = $(".mat-input-element");
if ($(formuleInput).is(':focus')) {
formuleInput[0].addEventListener('keyup', function(f) {
let caretPos = f.target.selectionStart;
console.log(caretPos);
let fInput = formuleInput[0].value;
if (e.keyCode === 32 && $(formuleInput).is(':focus')) {
e.preventDefault();
fInput = fInput.slice(0, caretPos) + fInput.slice(caretPos + 1);
formuleInput[0].value = fInput;
}
})
}})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="mat-input-element">
Comments
Post a Comment