Verify Custom properties during Test Taking

Use Case: A code can be assigned to a test and the learner is required to enter that code in order to take the test.

Initial Setup (one time)

  • SETUP:  Site-level - Add a custom property of ENABLE_TEST_WATCH=true in the Site Admin --> Customization tab.
  • Create a data source in the CMS, give it the name test-watcher.js, and add JavaScript code to check if passcode validation is required and, if required, prompt the user to enter a passcode when the test starts and verify that the passcode is entered correctly (as defined in test's custom property).


Adding a Passcode in the Test

    In the test, two custom properties need to be added.

     PASS_CODE_VERIFY  - true

     PASS_CODE - <code value> [multiple comma-seperated valid codes can be assigned.]


Learner's Flow:

When a user clicks the Take Test button, a dialog box appears to prompt them to enter the passcode. The entered passcode is validated and the user can proceed after entering a valid passcode.


JS Code ( Add in data source - test-watcher.js)

<!-- PASS_CODE Verify start -->
eb_TestWatcher = {
    verificationNeedChecked: false,
    verificationNeeded: false,
    verified: false,
    match: false,
    constructed: null,    
    exp_passcode: null,
    pass_codes: null,
    questionShown : function(index, widg){
        if(this.verificationNeedChecked && !this.verificationNeeded){return;}
          if(widg.viewController.test.customProperties && widg.viewController.test.customProperties.length > 0){
            for(var i=0; i<widg.viewController.test.customProperties.length; i++){
               if(widg.viewController.test.customProperties[i].name == 'PASS_CODE_VERIFY' && widg.viewController.test.customProperties[i].value == 'true'){
                  this.verificationNeeded = true;               
              if(widg.viewController.test.customProperties[i].name == 'PASS_CODE') {
                  exp_passcode = widg.viewController.test.customProperties[i].value;
                  pass_codes = exp_passcode.split(",")
          this.verificationNeedChecked = true;
        var num = widg.viewController.test.testQuestions.length;
              this.constructed = $(document.createElement('div'));
this.constructed.html("<b>Please enter passcode</b><br/>Passcode: <br/> <input type='text' id='vr_passCode'/>");
           var me = this;
                 autoOpen: false, modal: true,
                 buttons: {
                   Verify: function() {me.verify();}
    verify: function() {
        var me = this;
        if($("#vr_passCode").val() == ""){alert("Please enter passcode"); return;}
        for(var i=0; i<pass_codes.length; i++){
         if($("#vr_passCode").val() == pass_codes[i]){
            me.match = true;
        if(me.match == true){alert("Thanks, Code Verified, Please Proceed!"); me.verified = true; me.constructed.dialog("close"); }
else{alert("Sorry, passcode is incorrect");  }