Skip to content

Commit

Permalink
fix: additional correct field input conversion for xtextEntryInteraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill-Hatalski committed Jan 12, 2024
1 parent 7336dcf commit e4c68db
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
44 changes: 44 additions & 0 deletions views/js/qtiCreator/helper/textEntryConverterHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2019-2023 Open Assessment Technologies SA ;
*/

define([
'jquery',
'util/locale',
'util/converter'
], function ($, locale, converter) {
'use strict';

function textEntryConverterHelper(value, attributes) {
const numericBase = attributes.base || 10;
const convertedValue = converter.convert(value.trim());
switch (attributes.baseType) {
case 'integer':
value = locale.parseInt(convertedValue, numericBase);
return isNaN(value) ? '' : value;
case 'float':
value = locale.parseFloat(convertedValue)
return isNaN(value) ? '' : value;
case 'string':
return convertedValue;
default:
return '';
}
}

return textEntryConverterHelper;
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ define([
'taoQtiItem/qtiCreator/widgets/helpers/stringResponse',
'taoQtiItem/qtiCreator/widgets/states/factory',
'taoQtiItem/qtiCreator/widgets/states/Correct',
'taoQtiItem/qtiCommonRenderer/helpers/instructions/instructionManager'
], function ($, __, stringResponseHelper, stateFactory, Correct, instructionMgr) {
'taoQtiItem/qtiCommonRenderer/helpers/instructions/instructionManager',
'taoQtiItem/qtiCreator/helper/textEntryConverterHelper'
], function ($, __, stringResponseHelper, stateFactory, Correct, instructionMgr, textEntryConverterHelper) {
'use strict';

function start() {
Expand All @@ -32,8 +33,10 @@ define([
const correctResponse = stringResponseHelper.getCorrectResponse(response);

$container.find('tr[data-edit=correct] input[name=correct]').focus().val(correctResponse);
$container.on('keyup.correct', 'tr[data-edit=correct] input[name=correct]', function () {
const value = $(this).val();
$container.on('blur.correct', 'tr[data-edit=correct] input[name=correct]', function () {
const $input = $(this);
let value = textEntryConverterHelper($input.val(), response.attributes);
$input.val(value);
stringResponseHelper.setCorrectResponse(response, `${value}`, { trim: true });
});
instructionMgr.appendInstruction(this.widget.element, __('Please type the correct response in the box below.'));
Expand Down

0 comments on commit e4c68db

Please sign in to comment.