Character count in the Essay question

Character count in the Essay question

by Dominique Bauer -
Number of replies: 5
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello all,

I am opening a new discussion on counting characters since a previous discussion ↗ which had opened on the same subject has drifted on counting words, not characters.

The purpose of this post is simply to present a script that counts the characters in the Essay question. All there is to do is copy the script into the question's HTML code, and set the minimum and maximum number of characters. Note that the script can be placed elsewhere so that it applies to more than one question at a time.

The same script works when the "Response format" is set to "HTML editor" and using the Atto editor, and to "Plain text".

A different message is displayed when the number of characters is below the minimum, between the minimum and maximum, or above the maximum.

Using a script has several advantages, namely the script:

  • counts characters, which the Essay question does not,
  • does not require any installation,
  • works on all versions of Moodle,
  • does not need to be updated,
  • can easily be customized.

The script does not count spaces, non-breaking spaces, and new lines. Obviously, it also doesn't count HTML tags. It does not count list symbols (numbers or bullets).

It can be used for texts in English, Japanese and any other language.

You can try the question below at moodleformulas.org - Character count ↗.

Average of ratings: Useful (3)
In reply to Dominique Bauer

Re: Character count in the Essay question

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hi Dominique,
Thanks developing this. By any chance, have you created a Generico filter version of this?
In reply to AL Rachels

Re: Character count in the Essay question

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Al,

I have to thank you for mentioning the Generico filter, otherwise I might not have discovered this very nice tool.

The Generico filter is very convenient, even when you are not using all of its possibilities.

You probably know this better than I do, but for the benefit of those reading this thread, a Generico template is probably the best place to put a script, for example this little script for counting characters.

To answer your question, yes, I created a Generico template for the script. The script is available in two places at Character count ↗: in the question XML file and in the JavaScript file.

To create the Generico template, nothing could be easier. You just have to create a new template, give a name to "The key that identifies template xx" and "Template Name", copy the script into the "The body of template xx" field, and click "Save changes".

Then, in the text of the question, just add "{GENERICO:type=characterCount}" as shown below. And voila.

Since you are certainly more familiar with the Generico filter than I am, I am very open to any comments from you on this subject.



Average of ratings: Useful (2)
In reply to Dominique Bauer

Re: Character count in the Essay question

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Good thing I asked...I had the key and name right, but was trying to place the script down in the  Javascript Settings area. Works as depicted!

I have already added 3 versions of word and character counts to the Diary plugin, but have not worked on setting a minimum and maximum, yet.  I need to test on a couple more versions of Moodle before doing an interim release, but anyone who would like to see it in action can go to http://www.drachels.com/moodle311/, self register and enroll themselves into the, Diary Development, course. Been a while since I set up a course for others to access, so bawl me out if it doesn't work as expected. 🥵 If anyone would like to access the various versions of Diary I am setting up there, as a teacher, just let me know via message or email.

I have been putting it off, but due to these recent discussions regarding word and character counts, I finally installed and tried out the essay with auto grading plugin. Just call me green with envy! 🤢 I really hope to be able to implement some of the capabilities of the auto grading into the Diary plugin, but with all my daily distractions, I know it will be a while before I can show any progress. (I hate to admit it, but it took about 10 months worth of days, spread over three years to turn a copy of Journal into Diary.) 😵

Average of ratings: Useful (2)
In reply to AL Rachels

Re: Character count in the Essay question

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

😌 I finally had a chance between the constant interruptions, to finally add some worthwhile details of how to actually log in and see the current version of the Diary plugin.

Gotta go....