Taking Two inputs through modal in meteor.js, but its not working


#1

It works when I use only one text input in modal.This is my code, I am biggner in meteor.js. In main.html im using modal having two text inputs. When I tried using only one text input. It works. But Code shows nothing(console.log+no output) when I use two text inputs. . .

main.html

<head>
 <title>Note Manager</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" 
  rel="stylesheet">
 </head>

  <body>
  <nav class="green">
   <div class="container">
   <div class="nav-wrapper">
    <a href="#" class="brand-logo">Task Manager</a>
    <ul id="nav-mobile" class="right hide-on-med-and-down">
      {{#if currentUser}}
        <li class="nav-item">
           <a class="waves-effect waves-light btn" href="#addModal">Add Task</a>
        </li>
      {{/if}}
      <li class="nav-item">
        {{> loginButtons}}
      </li>
    </ul>
  </div>
</div>
</nav>
 <div class="container">
  <h1>Latest Tasks</h1>
  {{#if currentUser}}
    <ul class="collection">
    {{#each notes}}
      {{> note}}
    {{/each}}
    </ul>
   {{else}}
    <p>Nothing to display</p>
     <p>Please log in to manage your Tasks</p>
   {{/if}}
   </div>

{{> add}}

 <template name="note">
 <li class="collection-item">
   {{text1}}:{{text2}} <strong>Added by {{username}}</strong>
   <a href="#" class="delete-note secondary-content"><i class="material-icons">close</i></a>
  </li>
 </template>

Add Your Task

main.js

import { Template } from ‘meteor/templating’;
import { Notes } from ‘…/lib/collections.js’;
import { Accounts } from ‘meteor/accounts-base’;

// Accounts config
Accounts.ui.config({
passwordSignupFields:‘USERNAME_ONLY’
});

import ‘./main.html’;

Template.body.helpers({

notes(){
return Notes.find({});
}
});

Template.add.events({
‘submit .add-form’: function(){
event.preventDefault();

// Get input value
const target = event.target;
const text1 = target.text1.value;
const text2 = target.text2.value;

// Insert note into collection
/*
Notes.insert({
  text,
  ceratedAt: new Date(),
  owner: Meteor.userId(),
  username: Meteor.user().username,
});
*/

console.log(“Reached main.js”);
Meteor.call(‘notes.insert’, text1,text2);

// Clear form
target.text1.value = '';

target.text2.value = ‘’;

// Close modal
$('#addModal').modal('close');

return false;

}
});

Template.note.events({
‘click .delete-note’:function(){
//Notes.remove(this._id);
Meteor.call(‘notes.remove’, this);
return false;
}
});
collections.js

import { Mongo } from ‘meteor/mongo’;
import { Meteor } from ‘meteor/meteor’;
import { check } from ‘meteor/check’;

export const Notes = new Mongo.Collection(‘notes’);

Meteor.methods({
‘notes.insert’(text1,text2){
console.log(“Reached last”,text2);
check(text1, String);
check(text2, String);
//check(text2, String);
// Check if user is logged in
if(!Meteor.userId()){
throw new Meteor.Error(‘not-authorized’);
}

Notes.insert({
  text1,
  text2,
  ceratedAt: new Date(),
  owner: Meteor.userId(),
  username: Meteor.user().username,
});

},
‘notes.remove’(note){
check(note._id, String);

if(note.owner !== Meteor.userId()){
  throw new Meteor.Error('not-authorized');
}

Notes.remove(note._id);

}
});