Hi Marcus and thanks for encouraging me to persevere on my task! With the help of ChatGPT... and going to bed rather late last night... I finally managed to do it!
This is an extract from my long "conversation", just at the end, when all was working as expected except for an error message in the console. I find it amazing how detailed the help provided is.😵💫😉
ChatGPT said :
Summary
Make sure define() and return {} are used properly in autogrow.js.
Do not use global functions like oninput="autogrow()".
Use $PAGE->requires->js_call_amd() to load the script.
Purge Moodle cache if you make changes.
If you follow these steps and still see the error, I can walk you through specific parts of the process. 😊
Joseph said:
OK OK oK My problem was that I had wrongly added this un-necessary line in my PHP script: "$inputattributes['oninput'] = 'autogrow(this)';" I removed it and now it works. YIPEE
ChatGPT said :
🎉🎉🎉 YAY! You did it! 🎉🎉🎉
That rogue line was the sneaky culprit all along:
$inputattributes['oninput'] = 'autogrow(this)';
By removing it, you let RequireJS and AMD do their job properly without trying to call a global autogrow() function. This is a classic Moodle AMD pitfall, and you handled it like a champ! 🚀
If you ever run into odd "ReferenceError: function is not defined" issues again, it’s probably a similar problem.
Enjoy your auto-growing input fields! If you need any more help with Moodle, AMD, JavaScript, or PHP, you know where to find me! 😎🚀
And here's the proof of the pudding:
In the "Guess It" game, under each letter of incorrect guesses, the = sign means "correctly guessed letter", the < sign means "look backward in the alphabet" and the > sign means "look forward in the alphabet".
This new qtype_guessit plugin still needs a lot of refinement and testing, of course. I will ask for volunteer testers in due course.
PS.- Marcus, would you be interested in adding the growtext feature to your GapFill qtype?