Where does template.data of Blaze form go after first submit?


#1

Hello! I use {{> ArticleForm}} for create and update Articles in arabic-russian dictionary. I use blaze and ReactiveDict in my templates, after some problems with Autoform plugin.

First I was using it for update Article and everything works good. Now I added same form for create Article. I placed {{ > ArticleForm}} to {{> Header}} component, inside bootstrap modal, and call it by “+Add” button in top menu. It opens my form. First insert of Article works good. In DB there is new article, and even I redirected to new article. But at second call, template.data is empty and form is not interactive, it fires errors, because after update any field, ArticleForm should write ReactiveDict from template.data, but it doesn’t exist. I can’t understand, where goes template.data after firs successful insertion… Please answer if someone knows…

Here is how it looks:

Here is data context of my form :

Template.ArticleForm.helpers({
  article() {
    console.log("helper-article");
    if (!this.words) this.words = [{ note: "", word: "" }];
    if (!this.translations) this.translations = [{ translation: "" }];
    if (!this.synonyms) this.synonyms = [];
    if (!this.roots) this.roots = [];
    if (!this.subjects) this.subjects = [];
    //newWords, newTranslations - это добавление имен к элементам формы,
    //по которым можно будет отслеживать все изменения в форме
    let newWords = this.words.map((elem, index) => {
      return { note: elem.note, word: elem.word, wordId: `words.${index}` };
    });
    let newTranslations = this.translations
      ? this.translations.map((elem, index) => {
          return {
            translation: elem.translation,
            translationId: `translations.${index}.translation`,
            examples: elem.examples
              ? elem.examples.map((elem2, index2) => {
                  return {
                    example: elem2.example,
                    translation: elem2.translation,
                    exampleId: `translations.${index}.examples.${index2}`
                  };
                })
              : []
          };
        })
      : [];

    this.words = newWords;
    this.translations = newTranslations;
    this.picture = Session.get("picture");
    Template.instance().reactiveForm.set("article", this);
    const article = Template.instance().reactiveForm.get("article");
    return article;
  },
  deleted() {
    return this.deleted ? "checked" : "";
  },
  showMiddleHarakat(speachPart, index) {
    return speachPart == "глагол, I порода" && index == 0;
  },
  picture() {
    return Session.get("picture");
  }
});

Here is my template {{> ArticleForm}}

<template name="ArticleForm">
        <form id="articleForm-{{_id}}" class="panel panel-default article {{#if notPublished}}-opacity-06{{/if}}">
          <div class="panel-heading">
                <div class="panel-title words">
                    <div class="label label-info speach-part">{{speachPart}}</div><br />
                    <!-- Глагол 1й породы имеет дополнительную информацию для вывода, поэтому 
                    особый шаблон его вывода, например, среднекорневую глассную и масдары -->
                        {{#each article.words}}
                                <div class="wordEdit editField" id="{{wordId}}">
                                    <i class="glyphicon glyphicon-remove remove-word -remove" id="remove.{{wordId}}"></i>
                                    <input type="text" placeholder="прим." value="{{note}}" name="{{wordId}}.note" class="form-control note">
                                    <input type="text" placeholder="слово" value="{{word}}" name="{{wordId}}.word" class="form-control word -arabic-text-mid">
                                </div>
                            {{#if showMiddleHarakat ../speachPart @index}}
                                <div class="note middleHarakat" title="среднекорневая гласная настоящего времени">
                                        <input type="text" placeholder="скгнв" value="{{../middleHarakat}}" name="middleHarakat" class="form-control note">
                                </div>
                            {{/if}}
                        {{/each}}
                        <div class="add-word">
                                <i class="glyphicon glyphicon-plus"></i>
                        </div>
                </div>
          </div>
          <div class="panel-body">
                <div class="translations">
                    {{#each article.translations}}
                        <div class="translation">
                                <div class="editField editTranslation" id="{{translationId}}">
                                    <input type="text" name="{{translationId}}" value="{{translation}}" class="form-control" placeholder="перевод">
                                    <i class="glyphicon glyphicon-remove remove-translation -remove" id="remove.{{translationId}}"></i>
                                </div>
        
                                <div class="examples examples-form-{{../_id}}-{{@index}}">
                                        {{#each examples}}
                                            <div class="exampleEdit editField" id="{{exampleId}}">
                                                    <input type="text" placeholder="пример" value="{{example}}" name="{{exampleId}}.example" class="form-control example -arabic-text-mid">
                                                    <input type="text" placeholder="перевод примера" value="{{translation}}" name="{{exampleId}}.translation" class="form-control translation">
                                                    <i class="glyphicon glyphicon-remove remove-example -remove" id="remove.{{exampleId}}"></i>
                                            </div>
                                        {{/each}}
                                        <button class="btn btn-default btn-xs add-example" id="addExampleFor.{{translationId}}">
                                                <i class="glyphicon glyphicon-plus"></i>Пример
                                        </button>
                                </div>
                        </div>
                    {{/each}}
                    <button class="btn btn-default btn-sm add-translation">
                            <i class="glyphicon glyphicon-plus"></i>Перевод
                    </button>
                </div>
                {{> TagsSubjects}}
                {{> TagsSynonyms}}
                {{> TagsRoots}}
                <!--                 
                <div class="uploadImage">
                    {{> uploadForm}}
                    picture: {{picture}}
                </div> 
                -->
          </div>
          <div class="panel-footer">
            <button class="btn btn-primary article-save">Сохранить</button>
            <button class="btn btn-default article-edit-cancel">Отмена</button>
          </div>
        </form>
</template>

#2

no ideas ?
I have read all docs about blaze templates and didn’t’ find anything :frowning: