kerrickstaley / genanki

A Python 3 library for generating Anki decks
MIT License
2.06k stars 161 forks source link

Says field is missing when field is missing with {{Type:}} #85

Closed Zaxser closed 3 years ago

Zaxser commented 3 years ago

image but VerseText is clearly present

image

Here's the template, as this is likely the problem:

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">

<script>
  //Found here: https://gist.github.com/hinekidori/4085a1222af572057f1058d43cfce773
  //Script for modifying 'Show Answer' behavior for Input types.
  var htmlTextNodes = [];
  var innerHTMLText = [];
  var htmlNodeLength =document.getElementById('typeans').childNodes.length;
  var typedAnswer;
  var correctAnswer;
  var firstBr = null;
  var secondBr;

  //capture each node to array
  for (i = 0; i < htmlNodeLength; i++) {

   htmlTextNodes[i] = document.getElementById('typeans').childNodes[i];
   innerHTMLText[i] = document.getElementById('typeans').childNodes[i].innerHTML;

   //locate <br> tags for output change markers
   if (document.getElementById('typeans').childNodes[i].nodeName == "BR") {
    console.log("Runs if BR");
    if (firstBr != null) {
     secondBr = i;
    } else {
     firstBr = i;
    };
   };
  };

  //If answer is correct, firstBr will still be null, so must set to length of typeans.childNode
  if (firstBr == null) {
   firstBr = htmlNodeLength;
  };
  //assemble typed and correct answer strings
  typedAnswer = innerHTMLText.slice(0,firstBr).join("");
  var corr = document.getElementById('correctAnswer');
  correctAnswer = corr.innerHTML;

  //Modify answer output
  if (typedAnswer === correctAnswer) {
   var c = "<div id='correct'>"+typedAnswer+"</div>";
   var d = document.getElementById('typeans');
   d.innerHTML =  c;
  } else {
   var e = "<div id='incorrect'>"+typedAnswer+"</div>";
   var f = document.getElementById('typeans');
   f.innerHTML =  e;
  };
  </script><div class="front rote even container">
  <div class="row">
    <div class="field hint verse id col-12">
      {{BookName}} {{ChapterNumber}}:{{VerseNumber}}
    </div>
  </div>
  <div class="row">
    <div class="field hint even-words col-12">
      {{EvenWords}}
    </div>
  </div>
  <div class="row">
    <div class="type answer col-12">
      {{type: VerseText}}
    </div>
  </div>
</div>
Zaxser commented 3 years ago

Oh God. I figured it out. See that little space there? The one between "{{type:" and "VerseText}}"? Yes. That's what causes the problem. Removing it fixes it. Wow that bug is evil.

Zaxser commented 3 years ago

Closing the issue. Sorry.