Obsidian_to_Anki icon indicating copy to clipboard operation
Obsidian_to_Anki copied to clipboard

Fields not being properly recognized

Open matthew3wilson opened this issue 3 years ago • 9 comments

Certain fields are not being recognized, and the information that should belong in those fields is being added to whatever field I put on the previous line in the .md file. Here is an example card in Obisidian:

START Drugs

Trade Name: Adenosine(2) Generic Name: Adenoncard
Indication: SVT
Contraindications: hypersensitivity drug induced tach bradycardia How it Works: Decreases electrical conduction through AV node Side effects: - light headedness - hypotension - nausea Adult 1st Dose: 6mg Adult 1st Dose: 12mg Adult 1st Dose: 12mg Pedi 1st Dose: Pedi 2nd Dose: Pedi 3rd Dose: Footnotes: Fast IV, followed w/flush END

And here is what I get in the "Side effects" field: image

I've tried renaming the fields, ensuring the spelling is the same between Obsidian and Anki, and clearing the cache.

This happens with other fields as well.

matthew3wilson avatar Jun 02 '21 19:06 matthew3wilson

Hello! For you and anyone else having problem with this, I got a workaround. I also cleared cache to everything and didn't fix my problem. After that I tried disabling and enabling the extension and now it recognized the fields it didn't before.

Just in case it makes any difference, my steps were: 1- I disabled the plugin and closed the app. 2- Closed the app. 3- Open the app the again 4- Enabled the plugin.

I don't know if closing the app is needed, I just did it by coincidence.

erbara avatar Jun 23 '21 05:06 erbara

Possible reason

The issue had been bothering me for quite some time, and I did find some workaround that you can try. The reason why the fields are not being recognized is because the add-on identifies the note types and fields when it's first installed and enabled, and they're not modified automatically when changes are made in Anki.

As shown in the pics below, you can check note types and fields (FILE LINK FIELD) that are currently identified by clicking "Note Type Table" (which doesn't appear to be clickable I know 🥲). If the note types don't contain the targeted field names, which often occurs when they're added to Anki after installing Obsidian_to_Anki, then the targeted field syntax in notes will fail, and the content will be added to the previous field as described.

Screen Shot 2021-07-06 at 17 35 37 Screen Shot 2021-07-06 at 17 36 09

Temporary solution

The solution that works for me is actually pretty simple. I just uninstall, and install the add-on back for it to capture the note types and fields again. And check if the add-on successfully captures the note types and fields.

TR-792sp5ly avatar Jul 06 '21 10:07 TR-792sp5ly

The uninstall-reinstall workaround by @TR-792sp5ly worked for me as well.

andrewalseth avatar Aug 13 '21 20:08 andrewalseth

The uninstall-reinstall workaround by @TR-792sp5ly worked for me as well.

digitall-it avatar Nov 04 '21 17:11 digitall-it

A workaround without having to reinstall (and lose your settings) is to edit the settings file for the plugin directly. Open the file vault/.obsidian/plugins/obsidian-to-anki-plugin/data.json and scroll down to "fields_dict" to find your card type and fix the fields.

MudcrabDev avatar Jun 07 '22 07:06 MudcrabDev

The problem is because generation of FILE_LINK_FIELDS field in settings of data.json is only executed in the fresh install of this plugin:

        for (let note_type of this.note_types) {
            settings["CUSTOM_REGEXPS"][note_type] = "";
            const field_names = await invoke('modelFieldNames', { modelName: note_type });
            this.fields_dict[note_type] = field_names;
            settings["FILE_LINK_FIELDS"][note_type] = field_names[0];
        }
        return settings;

To fix this, we need to add the code to Regenerate Note Type Table button.

Leegenux avatar Sep 10 '23 11:09 Leegenux

The problem is because generation of FILE_LINK_FIELDS field in settings of data.json is only executed in the fresh install of this plugin:

        for (let note_type of this.note_types) {
            settings["CUSTOM_REGEXPS"][note_type] = "";
            const field_names = await invoke('modelFieldNames', { modelName: note_type });
            this.fields_dict[note_type] = field_names;
            settings["FILE_LINK_FIELDS"][note_type] = field_names[0];
        }
        return settings;

To fix this, we need to add the code to Regenerate Note Type Table button.

That's right, I desperately need to add a button like this.

Leiyi548 avatar Sep 24 '23 04:09 Leiyi548

Any update on this issues ? It was quite frustrating to find this out.

gorbach avatar Feb 17 '24 09:02 gorbach

I fixed it for myself 2 years ago: #301 I used this fix for a year. I no longer use this plulgin. If you are motivated, you can test it and add automated tests on my PR. I don't have time to do that right now.

tlgman avatar Feb 21 '24 11:02 tlgman