The code was too obvious so I didn’t add it. Here it is:
Body:
<head>
<title>sampleKeyup</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> eventTest}}
</body>
<template name="eventTest" id="test">
<h1>Event Test for KeyUP/KeyDown</h1>
<h2>First Test</h2>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
</template>
Events/Helpers:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
Template.hello.events({
'click #test'(event, instance) {
// increment the counter when button is clicked
console.log(event);
console.log("click registered");
;
},
'keyup'(event, instance) {
// increment the counter when button is clicked
console.log(event);
console.log("keyup registered");
;
}
});
I have tried all possible combinations by including/excluding the template id (#test). Using old/new syntax for declaring event handlers etc. Adding body beside click/keyup: ‘click body’/‘keyup body’.
It doesn’t work. The console remains mum.
The problem has happened before. Others have reported, as there in the links.
A solution has also been suggested as there in the second link. It works for the time being.
I forgot to add, that, the events works with ‘click’ on the ‘button’, & ‘keyup’ in ‘input’ etc. This has also been told 2 yrs. back in the above links.
It’s surely not as obvious as it looks. I am surely making a mistake! One of the mistakes I have caught. (below).
I actually had to make a new project to test this, coz my old code had by now expanded a lot.
I made an error!
Everyone pls. help.
Here is the new VALID code:
<head>
<title>sampleKeyup</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> eventTest}}
</body>
<template name="eventTest" id="test">
<div class="checkKeyUp">
<h1>Event Test for KeyUP/KeyDown</h1>
<h2>First Test</h2>
<div class="checkClick">
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
<p>Some Text Here</p>
</div>
<p>Some Text Here</p>
<p>Some Text Here</p>
</div>
</template>
And handlers:
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import './main.html';
Template.eventTest.events({
'click'(event, instance) {
// increment the counter when button is clicked
console.log(event);
console.log("click registered");
;
},
'keyup div'(event, instance) {
// increment the counter when button is clicked
console.log(event);
console.log("keyup registered");
;
}
});
I am very happy to report that ‘click’ is working on ‘div’ or ‘p’, …
'click div'
or,
'click p'
… & even without an element as in the code above. But as it should, it’s only working inside the template. Which is great!
‘keyup’ is not working any which way:
'keyup div'
'keyup p'
or plain:
'keyup'
WHAT am I doing wrong? Is this the correct way to use ‘keyup’?
For the “keyup” event to trigger, the event target must be an input element that can be typed in.
It will not work with ‘p’ and ‘div’ since you cannot type in there.
Try with an input element.