Created
June 24, 2014 12:53
-
-
Save sebdah/2ba471705a8e5bebfaf1 to your computer and use it in GitHub Desktop.
Tutorial: Writing your first Meteor application - Sending messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template name="input"> | |
<p>Message: <input type="text" id="message"></p> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Template.input.events = { | |
'keydown input#message' : function (event) { | |
if (event.which == 13) { // 13 is the enter key event | |
var name = 'Anonymous'; | |
var message = document.getElementById('message'); | |
if (message.value != '') { | |
Messages.insert({ | |
name: name, | |
message: message.value, | |
time: Date.now(), | |
}); | |
document.getElementById('message').value = ''; | |
message.value = ''; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment