After hours of trying and researching, I gave up …
I don’t want to use the normal Anki input field ({{type:xxx}}), I’d rather like to design my own input field using Bootstrap like this
<div class="d-flex justify-content-center section" style="height: 100px;">
<div class="input-group mb-3 input-group-sm rounded-pill overflow-hidden border w-50 my-auto">
<input type="text" class="form-control hide-focus border-0" placeholder="...." aria-label="Username"
style="height: 40px; font-size: 20px;" tabindex="1">
</div>
</div>
Details:
- Android 13
- Ankidroid 2.19.2
I’m able to focus my input field, but the virtual keyboard doesn’t appear - “Settings > Advanced > Type answer into the card” is turned on as described here.
Below’s what I`ve tried so far using Javascript code … combinations of proposals I found on MDN, stackoverflow and got from consulting the Codeium AI … nothing works.
It must be my mistake - can you give me any hint what’s wrong with my code?
Kind regards, Frank
<script>
// Get the input field element
const inputField = document.querySelector('input.form-control');
// Set the focus on the input field
inputField.focus();
// Programmatically trigger the keyboard to appear by simulating a key press event
inputField.dispatchEvent(new KeyboardEvent('keydown', { key: 'a' }));
requestAnimationFrame(() => {
console.log("**** requestAnimationFrame ****");
inputField.focus();
});
document.addEventListener('click', () => {
if ("virtualKeyboard" in navigator) {
console.log("**** focus ****");
navigator.virtualKeyboard.show();
}
});
inputField.addEventListener('focus', () => {
if ("virtualKeyboard" in navigator) {
console.log("**** focus ****");
navigator.virtualKeyboard.show();
}
});
console.log(document.activeElement);
// Assign an event handler to the input field
inputField.addEventListener('keydown', (event) => {
// Handle the key press event
console.log(`Key pressed => ${event.key}`);
if (event.keyCode === 13) {
// Handle the Return key press
console.log('Return key pressed!');
}
});
// function onPageFinished() {
// console.log("**** onPageFinished ****");
// var typedElement = document.querySelector("[name='typed']");
// if (typedElement) {
// typedElement.addEventListener("focus", taFocus);
// }
// // ...
// }
// onPageFinished();
</script>