Skip to content

Commit

Permalink
Fixed issue #17280: Can’t import a predefined bilingual label set whe…
Browse files Browse the repository at this point in the history
…n creating a single or a multiple choice question
  • Loading branch information
olleharstedt committed May 3, 2021
1 parent 36fced6 commit 467daf1
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions assets/scripts/admin/questionEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,11 @@ $(document).on('ready pjax:scriptcomplete', function () {
}

// TODO: Send as input, not in DOM.
$('body').append(`<input type="hidden" id="current_scale_id" value="${scaleId}" name="current_scale_id" />`);
if ($('#current_scale_id').length === 0) {
$('body').append(`<input type="hidden" id="current_scale_id" value="${scaleId}" name="current_scale_id" />`);
} else {
$('#current_scale_id').val(scaleId);
}

$('#labelsets').select2();
$('#labelsetpreview').html('');
Expand Down Expand Up @@ -755,7 +759,10 @@ $(document).on('ready pjax:scriptcomplete', function () {
// Awkward solution to the problem with looping through langs.
const langIds = {};

$.each(result, (lang, row) => {
const arr = Object.entries(result);
arr.forEach(function(entry) {
const lang = entry[0];
const row = entry[1];
if (lang.length !== 2) {
alert('Internal error: lang must have exactly two characters, but is ' + lang);
throw 'abort';
Expand Down Expand Up @@ -844,12 +851,16 @@ $(document).on('ready pjax:scriptcomplete', function () {
}
});

$('.answertable tbody').sortable('refresh');
updateRowProperties();
$('#labelsetbrowserModal').modal('hide');
$('#current_scale_id').remove();
});
});

// NB: Fails with Error: cannot call methods on sortable prior to initialization; attempted to call method 'refresh'
// Not needed?
//$('.answertable tbody').sortable('refresh');

updateRowProperties();
$('#labelsetbrowserModal').modal('hide');
$('#current_scale_id').remove();
}).catch(error => console.error(error));
}

/**
Expand Down

0 comments on commit 467daf1

Please sign in to comment.