Documentation

Check answers and reset

Each addon can react on user's selecting "Check answers" and "Reset" buttons. To do so, it is necessary to implement three other methods:

  • reset
  • setShowErrorMode – triggered when a user clicks on the "Check answers" button for the first time
  • setWorkMode – triggered when a user clicks on the "Check answers" button for the second time

By implementing these methods, the addon can show whether a user has selected the correct answer. This implementation can look as follows:

presenter.setShowErrorsMode = function () {  
    var $select = presenter.$view.find('.sample-question-select');  
    $select.attr('disabled', 'disabled');  

    if (presenter.getScore() === presenter.getMaxScore()) {  
        $select.css('border', '2px solid green');  
    } else {  
        $select.css('border', '2px solid red');  
    }  
};  

presenter.setWorkMode = function () {  
    var $select = presenter.$view.find('.sample-question-select');  

    $select.removeAttr('disabled');  
    $select.css('border', 'none');
};  

presenter.reset = function () {  
    presenter.setWorkMode();  
};