Documentation

Check answers and reset

Each addon can react to the user clicking the "Check answers" and "Reset" buttons. To apply this, it is necessary to implement three other methods:

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

By implementing these methods, the addon can show whether the 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();
};