Hello! This is my first post here, sorry if I’m not doing things in a right way.
Problem Statement
Say I have a note type with three fields A, B and C. How can I create a card template with a typing box such that, depending on a condition on the C field, the typing box expects field A or field B?
My main problem is that Anki has a strong condition on the presence of only one type field in a card template, and it seems to be a syntactic condition. For instance, the following does not work:
<div id=field>{{type:A}}</div>
<div id=c hidden>{{C}}</div>
<script>
var field = document.getElementById("field");
var c = document.getElementById("c");
if (cond(c)) {
field.innerHTML = "{{type:B}}";
}
</script>
I also tried some different approaches but in each case I have to write somewhere in my HTML {{type:A}} and {{type:B}}, which inevitably isn’t allowed by Anki.
Solutions ?
Some of the non-optimal solutions I thought about are the following:
- Manually fill a D field in my note which will contain A or B depending on C (but I have a lot of cards and this will take a lot of time, furthermore I would have to do this for every new card I add to my deck)
- Use the add-on allowing more than one type field per template, but this does not work on my version of Anki
- Not care, never change the type field and answer B when I know that I should and not worry about Anki telling me I’m wrong (though this maybe defies the point of a type field)
- Not care bis and remove the type field in the B case
If I had access to the code of type fields in Anki I think I would be able to slightly modify it in order to suit my needs, but I have been unable to find it anywhere. And maybe some of you have new ideas that I did not have? Or, maybe, you can confirm that what I want to do is impossible in vanilla anki.
Thanks anyway for reading.
Context
I’m using Anki to learn japanese vocabulary, and I use a type field in the english to japanese direction, in order to also teach myself kanjis.
However, some very frequently used japanese words are usually written without kanjis - only with kanas - though they have an official kanji spelling. I would then like Anki to expect the kana spelling when this is the mostly used one, and the kanjis otherwise. My problem is that I get my cards from Takoboto (which is very useful for a number of reasons: example sentences, multiple meanings of a word, quick card generation) and the generated cards have two main fields: Japanese (the kanjis) and Reading (the kanas), and even for words usually written in kanas, the Japanese field contains kanjis. Thus, I would like to switch between {{type:Japanese}} and {{type:Reading}} depending on the situation.
One could argue that the type field is unneeded when the japanese word is only written in kanas, since there is no kanji to learn, and that’s a fair point — maybe I’ll end up doing this if there’s no more practical solution. But I feel like typing my answer makes me more active in my recalling than imagining it in my head, so I would be happy keeping a type field for this case too.