var Chat = module.exports = Document.define("Chat")
.key("name", { length: [1, 18] })
.key("content", { length: [1, 140] })
module.exports = ListView.define("ChatView")
.template("/templates/chats/list.html")
.subView("#newChatForm", NewChatView)
module.exports = View.define("NewChatView")
.action("submit #newChatForm", function(event, element) {
event.preventDefault()
var chatInput = element.find(".chat")
, chat = chatInput.val()
chatInput.val("")
var name = element.find(".name").val()
Chat.create({ content: chat, name: name })
})
Controller("/chat", function(app) {
app.get(function() {
this.view = new ChatView(Chat.find())
})
})
<section>
<ul class = "chats">
<li class = "chat">
<div>
<span class = "createdAt" data-date-from-now></span> <span class = "name"></span> said:
</div>
<div class = "content"></div>
</li>
</ul>
<form id = "newChatForm">
<label for="name">name:</label><input type = "text" class = "name">
<label for="chat">message:</label><input type = "text" class = "chat">
<input type = "submit" value="send">
</form>
</section>
IE support coming in the near future.