Extensions/Assessment/essayLimitByCharacter

Extensions add specific functionality to Items API. They rely on modules within LT being available.

--

This script changes the essay validation check on string length to be character based, instead of the default word based.

It ignores spaces by default, so they are not treated as characters to validate length.

Works with longtextV2 and plaintext question types.

Methods

run(includeSpaces)

Looks for relevent question types and overrides validation to be on character length. Uses the max_length (Word limit) that was set up in authoring, treating the value as a character length instead of word length.

Known limitations

If the assessment player is in responsive mode (< 800px) and you don't have the review screen enabled (which it is by default) then we can't inject a custom button. This means we render the default Finish button, and no prevent submission will occur. The solution is to use any of the valid regions (main, horizontal, or horizontal-fixed) and don't decouple the submit button from the review button in Items API configuration.

Essentially, if you're using default options, you'll be fine.

If submitting via the JavaScript submit() method, this will skip the validation check.

Preventing submission

By default, questions are authored to prevent the user from submitting their session in the event of word limit violations. The same behaviour is inherited in this extension. If you don't want to prevent submission, you can check the Submit over limit option in the question authoring area.

To prevent submission, we need to add a custom button to Items API becuase we can't easily inject a validation check when the default submit button is clicked, so we need to replace it with a custom one.

Adding a custom button is a capability in Items API. Below is a code snippet of an Items API configuration object. Note the custom button is added in region_overrides.

You MUST use the icon_class and name as defined in the custom button options object below.

main region

{
    "config": {
        "regions": "main",
        "region_overrides": {
            "bottom-right": [
                {
                    "type": "custom_button",
                    "options": {
                        "name": "btn-essay-character-limit-submit",
                        "label": "Finish",
                        "icon_class": "item-next hidden"
                    },
                    "position": "right"
                },
                {
                    "type": "next_button",
                    "position": "right"
                },
                {
                    "type": "previous_button",
                    "position": "right"
                }
            ]
        }
    }
}

horizontal or horizontal-fixed regions

{
    "config": {
        "regions": "horizontal",
        "region_overrides": {
            "bottom": [
                {
                    "type": "custom_button",
                    "options": {
                        "name": "btn-essay-character-limit-submit",
                        "label": "Finish",
                        "icon_class": "item-next hidden"
                    },
                    "position": "right"
                },
                {
                    "type": "next_button",
                    "position": "right"
                },
                {
                    "type": "horizontaltoc_element",
                    "position": "right"
                },
                {
                    "type": "previous_button",
                    "position": "right"
                }
            ]
        }
    }
}

Changing labels

This extension will automatically change Word Limit to Character Limit in the footer of the essay question types. However, for full coverage in review mode, or in authoring and reporting, you should use label bundles. Eg:

Assessment label bundle

Use this in Items and Reports APIs.

Caveat: this will update Math Essay and Chemistry Essay footers as well.

{
    "config": {
        "questions_api_init_options": {
            "labelBundle": {
                "wordLength": "Character Limit"
            }
        }
    }
}

Authoring label bundle

Use this in Author API.

{
    "config": {
        "dependencies": {
            "question_editor_api": {
                "init_options": {
                    "label_bundle": {
                        "help.longtextV2.name:max_length": "Character limit",
                        "help.longtextV2.name:show_word_limit": "Character limit",
                        "help.longtextV2.description:max_length": "Maximum number of characters that can be entered in the text entry area (max 10,000 characters).",
                        "help.longtextV2.description:show_word_limit": "Defines whether the character limit should be displayed in the toolbar or not. The options are: <ul><li><strong>Always On</strong> - Character Limit is always displayed.</li><li><strong>On Limit</strong> - Character Limit will only be displayed when the limit is reached.</li><li><strong>Off</strong> - Character Limit will not be displayed.</li></ul>",
                        "help.longtextV2.description:submit_over_limit": "Determines if the user can save/submit text when the character limit has been exceeded.",
                        "longtextV2:max_length": "Character limit",
                        "longtextV2:show_word_count": "Show character count",
                        "longtextV2:show_word_limit": "Character limit",
                        "help.plaintext.name:max_length": "Character limit",
                        "help.plaintext.name:show_word_limit": "Character limit",
                        "help.plaintext.description:max_length": "Maximum number of characters that can be entered in the text entry area (max 10,000 characters).",
                        "help.plaintext.description:show_word_limit": "Defines whether the character limit should be displayed in the toolbar or not. The options are: <ul><li><strong>Always On</strong> - Character Limit is always displayed.</li><li><strong>On Limit</strong> - Character Limit will only be displayed when the limit is reached.</li><li><strong>Off</strong> - Character Limit will not be displayed.</li></ul>",
	                    "plaintext:max_length": "Character limit",
                        "plaintext:show_word_limit": "Character limit"
                    }
                }
            },
            "questions_api": {
                "init_options": {
                    "labelBundle": {
                        "wordLength": "Character Limit"
                    }
                }
            }
        }
    }
}
Since
0.10.0
Example
import { LT } from '@caspingus/lt/src/assessment/index';

LT.init(itemsApp); // Set up LT with the Items API application instance variable
LT.extensions.essayLimitByCharacter.run();
Parameters:
Name Type Description
includeSpaces boolean

Whether to include spaces in the character count Default is false.