Forum Discussion

NickiMazzocca-8's avatar
NickiMazzocca-8
Community Member
2 months ago

Text Entry Minimum Character Requirement

I am trying to create a text entry field with a minimum character requirement in order to submit.  I have absolutely no idea how to do this. 

Scenario:

My students need to write a reflection that is at least 50 words before they can submit.  It is ungraded, but participation is required in order to move forward.

Important facts:

  • I have never once dabbled in JavaScript or anything similar, especially when it comes to Storyline.  I have seen some people addressing the issue on the boards, but their answers may as well be in Greek due to my beginner standing. (Most "help" leads to a miles-long thread that still doesn't answer the question.)
  • If you know the answer to this conundrum, please explain it to me like I'm five years old.  I'm sure it is a frustrating request, but from where I am sitting it is a necessary one.

This seems like it should be a standard feature for an educational platform, so I might have just missed something in my training for Storyline.  I truly appreciate any help that anyone is willing to share, and thank you for your patience.

  • Hi NickiMazzocca-8,

    I have provided a storyline file with an example of this. It does require JavaScript, but you should just be able to add to your project.

    Here's the outcome on Review 360 before you get into it.

    In my example, I have added a message below the text area indicating how many words have been typed.

    This solution uses two variables, these are:

    name: minWords
    Type: Number
    Value: 50

    name: wordCountMessage
    Type: Text
    Value: 

    name:wordCountReached
    Type: True/False
    Value: False

    I then add an input box to the slide, and ensure it is set to Multi-line, but selecting the input box, and selecting CTRL+ENTER and then selecting Text Box and then Text Entry > Multi-line.

    I then add a single line Text Box below the Multi-line text input, and add the variable %wordCountMessage% to the contents of the Text Box. The variable name is displayed with a yellow background, to indicate it is a variable reference, and dynamic text.

    I then add an icon to the slide which has two states, to visually indicate if the minimum requirement has been met. The Normal state is a cross icon and the Tick state is a tick icon. I use the variable wordCountReached to switch between the two states.

    I then add a trigger to change the state of the icon when the variable wordCountReached is changed between True/False. True = Tick (Tick state of icon), False = Cross (Normal state of icon)

    I then add the following JavaScript to the "timeline starts on this slide - Execute JavaScript" trigger. This will control the variables in Storyline which will either update text, or cause the icon to switch to the Tick or Cross.

    // Get the Storyline Player
    const player = GetPlayer();
    // Get the text area
    const textarea = document.querySelector('textarea');
    // Get the number of minimum words required
    const minWords = player.GetVar('minWords')
    // Add the event listener
    textInput = function()
    {
        const text = textarea.value.trim(); // Get the text and trim whitespace
        const words = text.split(/\s+/).filter(word => word.length > 0); // Split text into words
        const wordCount = words.length; // Count the words
        player.SetVar('wordCountMessage',`You have typed ${wordCount} words. Minimum required is ${minWords}.`);
        player.SetVar('wordCountReached',wordCount >= minWords);
    }
    textarea.addEventListener('input', textInput);
    // run to init
    textInput();

     

  • Hi NickiMazzocca-8,

    I have provided a storyline file with an example of this. It does require JavaScript, but you should just be able to add to your project.

    Here's the outcome on Review 360 before you get into it.

    In my example, I have added a message below the text area indicating how many words have been typed.

    This solution uses two variables, these are:

    name: minWords
    Type: Number
    Value: 50

    name: wordCountMessage
    Type: Text
    Value: 

    name:wordCountReached
    Type: True/False
    Value: False

    I then add an input box to the slide, and ensure it is set to Multi-line, but selecting the input box, and selecting CTRL+ENTER and then selecting Text Box and then Text Entry > Multi-line.

    I then add a single line Text Box below the Multi-line text input, and add the variable %wordCountMessage% to the contents of the Text Box. The variable name is displayed with a yellow background, to indicate it is a variable reference, and dynamic text.

    I then add an icon to the slide which has two states, to visually indicate if the minimum requirement has been met. The Normal state is a cross icon and the Tick state is a tick icon. I use the variable wordCountReached to switch between the two states.

    I then add a trigger to change the state of the icon when the variable wordCountReached is changed between True/False. True = Tick (Tick state of icon), False = Cross (Normal state of icon)

    I then add the following JavaScript to the "timeline starts on this slide - Execute JavaScript" trigger. This will control the variables in Storyline which will either update text, or cause the icon to switch to the Tick or Cross.

    // Get the Storyline Player
    const player = GetPlayer();
    // Get the text area
    const textarea = document.querySelector('textarea');
    // Get the number of minimum words required
    const minWords = player.GetVar('minWords')
    // Add the event listener
    textInput = function()
    {
        const text = textarea.value.trim(); // Get the text and trim whitespace
        const words = text.split(/\s+/).filter(word => word.length > 0); // Split text into words
        const wordCount = words.length; // Count the words
        player.SetVar('wordCountMessage',`You have typed ${wordCount} words. Minimum required is ${minWords}.`);
        player.SetVar('wordCountReached',wordCount >= minWords);
    }
    textarea.addEventListener('input', textInput);
    // run to init
    textInput();

     

    • NickiMazzocca-8's avatar
      NickiMazzocca-8
      Community Member

      You really are a super hero!  This worked spectacularly!!!  Thank you so much.  I hope it gains some views because I saw a ton of people looking for a similar solution to their issue.  You're the best and you did an excellent job walking me through it step-by-step.

    • LesB's avatar
      LesB
      Community Member

      Hi SamHill 

      I have an advanced developer who is helping me to limit the characters.

      He tried this and other suggestions but it only works for 1 entry box on a slide. 

      I have multiple slides with up to 3 entry boxes on each slide.

      Once done, the user can export the editable PDF. That's why we need the limitations.

      Suggestions? Thanks 

      • SamHill's avatar
        SamHill
        Super Hero

        Hi LesB yes, this is for one textarea only. Is you developer advanced in JavaScript? If so, just let them know they need to make adjustments to this code:

        const textarea = document.querySelector('textarea');

        And change to:

        const textarea = document.querySelectorAll('textarea');

        And then loop through the results and apply the input listener to the individual textareas.