отправить изменения в форму в метеоре; объект JavaScript - PullRequest
0 голосов
/ 15 января 2019

Я пытаюсь сохранить изменения в редактировании формы после ее отправки. Но в режиме редактирования, когда нажата кнопка сохранения изменений, возникает ошибка: Uncaught TypeError: Невозможно прочитать свойство 'value' из undefined в Object.submit появляется #updateLogDetails (SingleDailylog.js: 228).

Template.SingleDailylog.onCreated(function(){
  this.autorun(()=>{
  this.subscribe('dailylog');
  });
  const id = FlowRouter.getParam('id');
  this.dailyLog = new ReactiveVar();
  this.dailyLog.set(this.data._id);
  this.editForm = new ReactiveVar(false);
  });

Template.SingleDailylog.onRendered(function(){
  $( "#updateLogDetails" ).validate();
  });

Template.SingleDailylog.events({
  'submit #updateLogDetails'(event,template){
    event.preventDefault();
    const target = event.target;
    const updateLogObj = {
        personInCharge: target.personInCharge.value,
        project1: target.project1.value,
        weather: target.weather.value
        };
        swal({
      title: 'Update Details?',
      text: 'Choose confirm to update details.',
      icon: 'warning',
      buttons: {
        cancel: {
          text: 'Cancel',
          value: false,
          visible: true,
          className: "",
          closeModal: true
        },
        confirm: {
          text: "Confirm",
          value: true,
          visible: true,
          className: "",
          closeModal: false
        }
      }
    })
    .then((value)=>{
      if(value){
        Meteor.call('updateLogDetails', updateLogObj, function(error,result){
          if(error){
            swal("Error!", error.message, "error");
          }else{
            swal("Details Updated!", "Your changes have been updated in the system.", "success");
            template.editForm.set(false);
          }
        });
      }
    });
  }
});
<template name="SingleDailylog">
  {{#if Template.subscriptionsReady }}
  <div class="card daily-report-master-container">
    <div class="row d-block clearfix">
      <div class="col">
        <button id="editForm" class="btn btn-primary float-right">{{#if editForm}}Close Edit{{else}}Edit Details{{/if}}</button>
      </div>
    </div>
    <div id="page-contents" class="card-contents">
      <div class="row daily-report-header">
        <div class="col s4">
          <p class="daily-report-title">Daily Log Report</p>
        </div>
        <div class="col s5">
          <p class="daily-report-date">Log Date: {{date}}</p>
        </div>
      </div>

      {{#if editForm}}
        <form id="updateLogDetails" class="updateLogDetails">
          <div class="form-row">
            <div class="form-group col-md-6">
              <input value="{{personInCharge}}" type="text" class="form-control" placeholder="Name">
              <label for="first">Person In Charge</label>
            </div>
            <div class="form-group col-md-6">
              <input value="{{project1}}" type="text" class="form-control" placeholder="Site">
              <label for="first">Project Site</label>
            </div>
            <div class="form-group col-md-6">
              <input value="{{weather}}" type="text" class="form-control" placeholder="Weather">
              <label for="first">Weather</label>
            </div>
            <button type="submit" class="btn btn-primary">Save Changes</button>
          </div>
        </form>
          </div>
            {{else}}
      <div class="row daily-report-details-container">
        <div class="col s4">
          <p class="daily-report-header-item-content">{{personInCharge}}</p>
          <span class="daily-report-header-item-title">Person In Charge</span>
        </div>
        <div class="col s4">
          <p class="daily-report-header-item-content">{{project1}}</p>
          <span class="daily-report-header-item-title">Project Site</span>
        </div>
        <div class="col s4">
          <p class="daily-report-header-item-content">{{weather}}</p>
          <span class="daily-report-header-item-title">Weather</span>
        </div>
      </div>
      </div>
  </div>
{{/if}}
</template>

Как мне найти значение?

...