Merge pull request #1359 from cryptpad/question_duplication_bugfix

Fixes issue with duplicating choice/checkbox grid questions
This commit is contained in:
yflory 2024-01-16 16:08:42 +01:00 committed by GitHub
commit e61b2aba63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -733,6 +733,11 @@
return !(typeof(Atomics) === "undefined" || !supportsSharedArrayBuffers() || typeof(WebAssembly) === 'undefined');
};
//Returns an array of integers in range 0 to (length-1)
Util.getKeysArray = function (length) {
return [...Array(length).keys()];
};
if (typeof(module) !== 'undefined' && module.exports) {
module.exports = Util;
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {

View File

@ -3296,7 +3296,7 @@ define([
});
sorted.forEach(function (uid) {
var answer = answers[uid];
var viewOnly = content.answers.cantEdit || APP.isClosed;
var action = h(viewOnly ? 'button.btn.btn-secondary' : 'button.btn.btn-primary', [
@ -4110,9 +4110,27 @@ define([
idx = obj.idx;
_uid = Util.uid();
var opts = Util.clone(content.form[uid].opts);
if (type === 'multiradio' || type === 'multicheck') {
var itemKeys = Util.getKeysArray(content.form[uid].opts.items.length);
var valueKeys = Util.getKeysArray(content.form[uid].opts.values.length);
opts.items = itemKeys.map(function (i) {
return {
uid: Util.uid(),
v: content.form[uid].opts.items[i].v
};
});
opts.values = valueKeys.map(function (i) {
return {
uid: Util.uid(),
v: content.form[uid].opts.values[i].v
};
});
}
content.form[_uid] = {
q: content.form[uid].q,
opts: content.form[uid].opts,
opts: opts,
type: type,
};