Answer the question
In order to leave comments, you need to log in
How to display the entire Meteor.js form?
Guys, I don't know how to display 1+ input.
There is such a code: 1) html 2) js
Displays only 1 input, when I want to add a second one, it bugs ...
PS I need to display 2-3 inputs by clicking on the button.
<body>
<div class="container">
<header>
<h1>Todo List</h1>
<form class="new-task">
<input type="text" name="text" placeholder="Type to add new tasks" />
</form>
</header>
<ul>
{{#each tasks}}
{{> task}}
{{/each}}
</ul>
</div>
</body>
<template name="task">
<li>{{text}}</li>
</template>
import { Template } from 'meteor/templating';
import { Tasks } from '../api/tasks.js';
import './body.html';
Template.body.helpers({
tasks() {
// Show newest tasks at the top
return Tasks.find({}, { sort: { createdAt: -1 } });
},
});
Template.body.events({
'submit .new-task'(event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form element
const target = event.target;
const text = target.text.value;
// Insert a task into the collection
Tasks.insert({
text,
createdAt: new Date(), // current time
});
// Clear form
target.text.value = '';
},
});
Answer the question
In order to leave comments, you need to log in
Answer:
html
<form class="new-task">
<input type="text" name="text" placeholder="Type to add new tasks" />
<input type="text" name="text2" placeholder="Type to add something else" />
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question