Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor.js submit event

Tags:

meteor

I was just playing around a bit with Meteor.js when I ran into this strange issue, I have a form with two textfields, but somehow my event is not listening to the submit. When I remove one textfield, everything works fine ...

Below is my template for the form:

<template name="new_timer">
    <div class="timer timer--empty">
        <form id="new_timer">
            <input type="text" name="timer__name" class="timer__name" placeholder="Timer name">
            <input type="text" name="timer__description" class="timer__description" placeholder="Timer description">
        </form>
    </div>
</template>

And on the client side:

Template.new_timer.events({
    'submit form': function(e) {
        console.log('new timer');

        e.preventDefault();
    }
})

This doens't seem to work, however when I change my template to the following, it works

<template name="new_timer">
    <div class="timer timer--empty">
        <form id="new_timer">
            <input type="text" name="timer__name" class="timer__name" placeholder="Timer name">
        </form>
    </div>
</template>

Am I just overlooking something very basic here?

like image 787
woutr_be Avatar asked Nov 23 '25 17:11

woutr_be


1 Answers

You might add an event like

'keyup form': function(e) {
    if (e.keyCode === 13) {
        // do something
    }
}

Basically using a submit in a single page application is not adapted. In this kind of application everything is event based, you never reload a page so you never really 'submit' a form.

The 'form' tag becomes useless, most of developers (including me) are keeping it by habit but it is not required.

It is a bit late for an answer, I hope it can help somebody else!

like image 178
Ageo Avatar answered Nov 25 '25 10:11

Ageo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!