@Muxailo

Как выводить всю форму Meteor.js?

Ребята, не знаю как вывести 1+ инпут
Есть такой код: 1) html 2)js
Выводит только 1 инпут, когда я хочу добавить второй, багаеться...
P.S. надо выводить 2-3 интупа по клику на кнопку.
<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 = '';
  },
});
  • Вопрос задан
  • 159 просмотров
Решения вопроса 1
@Muxailo Автор вопроса
Ответ:
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>

js:

const target = event.target;
const text = target.text.value;
const text2 = target.text2.value;

Tasks.insert({ text, text2, createdAt: new Date() });
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы