ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.43k stars 2.19k forks source link

[BUG]: Modifying typed answer with JS works inconsistently #16213

Open Eltaurus-Lt opened 5 months ago

Eltaurus-Lt commented 5 months ago

Checked for duplicates?

Does it also happen in the desktop version?

What are the steps to reproduce this bug?

  1. Enable 'Type answer into the card' in the settings
  2. add the following script to the Front side of a card in the Basic (type in the answer) Note Type:
    <script>
    document.getElementById('typeans').value = 'a';
    </script>
  3. During the review submit an answer by pressing the "Show answer" button

Expected behaviour

The back of the card is expected to show, that the submitted answer is 'a'. (it does so on Anki desktop)

Actual behaviour

The back of the card shows that an empty answer was submitted.

Debug info

AnkiDroid Version = 2.17.6 (568538896be943818ca793dd2635822265712def)

Backend Version = 0.1.34-anki23.12.1 (23.12.1 1a1d4d5419c6b57ef3baf99c9d2d9cf85d36ae0a)

Android Version = 11 (SDK 30)

ProductFlavor = play

Manufacturer = HMD Global

Model = Nokia C01 Plus

Hardware = T19545AA1

Webview User Agent = Mozilla/5.0 (Linux; Android 11; Nokia C01 Plus Build/RP1A.201005.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/123.0.6312.118 Mobile Safari/537.36

ACRA UUID = bb072dd9-2ecf-49e6-81a4-c0e99b4f0fd8

Crash Reports Enabled = true

(Optional) Anything else you want to share?

If the Android keyboard is used to type anything else in the input field after it was modified with JS, the back of the card shows the full answer. E.g., if 'b' is manually typed after step 2 and before step 3, the submitted answer on the back of the card is correctly shown to be "ab".

It looks like AnkiDroid uses a separate variable to track the typed answer, instead of directly reading the value of html element, and this value is updated only when the on-screen keyboard is used. In that case, maybe it is possible to add the call of the updating function into the "Show answer" button as well to ensure that the submitted answer is always the same as what is displayed on the screen?

Research

oyeraghib commented 4 months ago

Hi @Eltaurus-Lt I would need your help with two things as I was not able to reproduce the above issue.

  1. Can you provide a mobile app video with showing what you have shared in (Optional) Anything else you want to share? section. I was able to reproduce the issue where it doesn't show the 'a' text on pressing Show answer but at the same time if user manually types b, I couldn't see it becoming ab. A video of that showing it would be really helpful.

  2. Secondly I tried it on Anki Desktop, it seems to be working in the same way as mobile, is it possible to show a video of that too where it works fine on desktop. Also the steps to reproduce remains same on desktop ? (As I was not able to find Step 1 there).

Thanks.

Eltaurus-Lt commented 4 months ago

Sure

  1. Here is the video for AnkiDroid: ankidroid It is recorded with Chrome remote debugging tools, so the interface is not visible. The sequence of buttons I press here during the review: Show AnswerAgain → Type 'b' with the appearing Android on-screen keyboard → Show Answer. You can see that the typed answer is empty on the back of the card the first time ("2" is the expected answer), while it is correctly displayed as "ab" the second time.
  2. Also the steps to reproduce remains same on desktop ? (As I was not able to find Step 1 there).

    Step 1 is for AnkiDroid solely, as it is required to disable the default Android input in favor of using the card HTML input field, which is the only input method on desktop as is.

    Here is the video that shows the reviewing of the same card as above on Anki desktop as well as its full code: anki desktop The typed answer is displayed correctly both times: "a" in the first case and "ab" in the second one. (my desktop version is "⁨23.12.1 (1a1d4d54)⁩ Python 3.9.15 Qt 6.6.1 PyQt 6.6.1" by the way)

Eltaurus-Lt commented 4 months ago

2. (my desktop version is "⁨23.12.1 (1a1d4d54)⁩ Python 3.9.15 Qt 6.6.1 PyQt 6.6.1" by the way)

I also just installed "Version ⁨24.04.1 (ccd9ca1a)⁩ Python 3.9.18 Qt 6.6.2 PyQt 6.6.1" and tested the card there. It works exactly the same.

github-actions[bot] commented 1 month ago

Hello 👋, this issue has been opened for more than 3 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically

Eltaurus-Lt commented 1 month ago

still searching for solutions

brishtibheja commented 3 weeks ago

I could reproduce on latest beta version.