I’m running Meteor 0.5.2 with the insecure package on + the coffeescript package on.
Cards = new Meteor.Collection "Cards"
if Meteor.isClient
Template.makeCard.events
# HANDLES SUBMISSION OF NEW CARD
'submit form.makeCardForm': ->
makeNewCard $("input.cardName").val(), $("input.percentage").val()
# GETS ALL THE CARDS
Template.viewCards.cards = ->
Cards.find {}
# METHODS
makeNewCard = (cardName, percentage) ->
# IF NO %GE GIVEN, DEFAULT TO 0
unless percentage
percentage = 0
# IF CARD NAME PRESENT
if cardName.length
Cards.insert
name: cardName,
progress: percentage
I’ve checked the correct values are being passed into the makeNewCard function. However, every time I submit the form, it shows up for a split second in the cards template, then disappears.
This problem does not happen when inserting records directly through the console.
Any help would be greatly appreciated.
I’m not that familiar with Meteor but I think I see your problem. You have a submit handler on you a form:
That handler isn’t returning false so the form submission will continue just like a normal
<form>submission; so you see the results you’re expecting for a split second and then the<form>submits to the server as usual and everything disappears.Compare this (http://jsfiddle.net/ambiguous/Q6cQr/):
and this (http://jsfiddle.net/ambiguous/XWkXG/):
and you should see the difference.
You probably just need to add a
return falseto your submit handler: