-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: additional correct field input conversion for xtextEntryInteraction
- Loading branch information
Kirill-Hatalski
committed
Jan 12, 2024
1 parent
7336dcf
commit e4c68db
Showing
2 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters