This Meteor client "simplified version" code needs to print "submitted" to the browser console when the keyboard enter key is touched/clicked but it does nothing.
Why and how to fix it? thx
Template.body.events({
'submit #myForm': function(e) {
e.preventDefault();
console.log('submitted'); //<=========
}
});
<body>
<form id="myForm">
{{> index}}
</form>
</body>
<template name="index">
<div id="main">
{{> content}}
</div>
</template>
<template name="content">
{{> Template.dynamic template=whichOne}}
</template>
<template name="search">
<input class="half" type="text" id="food" autocomplete="off">
</template>
In your input section in the search
template add listener to Enter key. Add this line:
onKeyPress={(event)=>{
if(event.key == 'Enter'){
// do whatever you like to do
}
}}
Here is a tiny example: https://jsfiddle.net/kxooyb3z/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.