Skip to content

Instantly share code, notes, and snippets.

@hellvispresley
Created June 3, 2014 15:36
Show Gist options
  • Save hellvispresley/51bfa290f05451da754d to your computer and use it in GitHub Desktop.
Save hellvispresley/51bfa290f05451da754d to your computer and use it in GitHub Desktop.
chatTutorial02
<head>
<title>chat</title>
</head>
<body>
{{> entryfield}}
{{> messages}}
</body>
<template name="entryfield">
<input type="text" id="name" placeholder="Name" /><input type="text" id="message" placeholder="Your Message"/>
</template>
<template name="messages">
<p>
{{#each messages}}
<strong>{{name}}</strong>- {{message}}
{{/each}}
</p>
</template>
Messages = new Meteor.Collection('messages');
if (Meteor.isClient) {
Template.messages.messages = function (){
return Messages.find({}, { sort: { time: -1 }});
};
Template.entryfield.events = {
"keydown #message": function(event) {
if(event.which == 13) {
//submit the form
var name = document.getElementById('name');
var message = doucment.getElementById('message');
if(name.value != '' && message.value != '') {
Messages.insert({
name: name.value,
message: message.value,
time: Date.Now()
});
name.value ='';
message.value='';
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment