Hello,
From my tests, < input wire:keydown.enter=“testMethod” > is executing the method only when the element is in focus.
Is there a way or a workaround so the "testMethod’ to be executed when the input element is not in focus, too?
Thank you,
Hello,
From my tests, < input wire:keydown.enter=“testMethod” > is executing the method only when the element is in focus.
Is there a way or a workaround so the "testMethod’ to be executed when the input element is not in focus, too?
Thank you,
There is indeed a way to achieve what you want.
You can use javascript to emit livewire event.
window.addEventListener("keydown", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
Livewire.emit('testMethod');
}
});
or this
document.addEventListener("keydown", function(event) {
event.preventDefault();
if (event.keyCode === 13) {
Livewire.emit('testMethod');
}
});
But let me remind you that this will be an awkward thing from UX design perspective.
Thank you, @ghostzero911
Yes. I am aware that this can be an awkward thing but in my case, I need it as described and it is used with care