Jenson Raby
Jenson Raby

Reputation: 789

how to submit a form in meteor?

This is my routing page

Router.route('/search', function () {
// render the Home template with a custom data context
this.render('search', {data: {title: 'My Title'}});
});

index.html

<head>
<title>Test</title>
</head>
<body>
</body>

search.html

<template name="search">
    <form class="new-task">
        <input type="text" name="text" placeholder="Type to add new tasks" />
        <input type="submit" value="submit">
    </form>
</template>

search.js

Template.body.events({
"submit .new-task": function (event) {
    // Prevent default browser form submit
    event.preventDefault();
    // Get value from form element
    var text = event.target.text.value;
    console.log(text)
    // Insert a task into the collection
    // event.target.text.value = "";
}
});

here i m not getting the text box value to the search.js ,page get reloded again and the url changed to http://192.168.1.33:3000/search?text=fgh when i submitting form

can anyone know how to solve this problem ?

Upvotes: 0

Views: 737

Answers (1)

val
val

Reputation: 793

You need to define your event handler on the search template:

Template.search.events({
    "submit .new-task": function(event){ /* ... */ }
});

Upvotes: 1

Related Questions