# Conditional type field

**URL:** <https://forums.ankiweb.net/t/conditional-type-field/67965>\
**Category:** Card Design\
**Created:** [December 26, 2025, 11:58pm UTC](https://forums.ankiweb.net/t/conditional-type-field/67965 "2025-12-26T23:58:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaznad](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kaznad](https://forums.ankiweb.net/u/Kaznad)\
**Post date:** [December 26, 2025, 11:58pm UTC](https://forums.ankiweb.net/t/conditional-type-field/67965/1 "2025-12-26T23:58:57Z")

</div>

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** :

```html
<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.

---

<div class="post-metadata">

**Author:** ![ZornHadNoChoice](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/zornhadnochoice/32/28874_2.png) [@ZornHadNoChoice](https://forums.ankiweb.net/u/ZornHadNoChoice)\
**Post date:** [December 27, 2025, 2:00am UTC](https://forums.ankiweb.net/t/conditional-type-field/67965/2 "2025-12-27T02:00:03Z")

</div>

Field D can contain anything, you just need to use [conditional replacement](https://docs.ankiweb.net/templates/generation.html?highlight=conditional#conditional-replacement).

---

<div class="post-metadata">

**Author:** ![Eltaurus](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/eltaurus/32/10287_2.png) [@Eltaurus](https://forums.ankiweb.net/u/Eltaurus)\
**Post date:** [December 27, 2025, 4:59am UTC](https://forums.ankiweb.net/t/conditional-type-field/67965/3 "2025-12-27T04:59:51Z")

</div>

To clarify a little bit. There are two ways this can be done:

1. Use a conditional replacement:

2. Use a custom typing HTML element and check the answer explicitly using JS, which will enable using any kind of condition (just as the first method, it can work on any platform).

---

<div class="post-metadata">

**Author:** ![Kaznad](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kaznad](https://forums.ankiweb.net/u/Kaznad)\
**Post date:** [December 28, 2025, 10:56am UTC](https://forums.ankiweb.net/t/conditional-type-field/67965/4 "2025-12-28T10:56:42Z")

</div>

Thanks a lot for your detailed answer. I think I will try the first method, and write a python script to fill a new field automatically for all my cards.  
Your code is great though, that’s impressive work, thanks for doing that for the community. But I don’t think my problem is worth spending a lot of time digging into your codebase to see what I can extract from it… Maybe I’ll try, at some point.

Thanks anyway!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [January 27, 2026, 10:57am UTC](https://forums.ankiweb.net/t/conditional-type-field/67965/5 "2026-01-27T10:57:13Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
