From ed28b5ec7b76b0bd509c7c8ef3245f0594e8ee56 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 9 Jul 2021 11:45:48 +0200 Subject: [PATCH] Randomize 'ordered list' initial state in forms --- www/common/common-util.js | 9 +++++++++ www/form/inner.js | 1 + 2 files changed, 10 insertions(+) diff --git a/www/common/common-util.js b/www/common/common-util.js index 51540a660..1fd78cec1 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -9,6 +9,15 @@ return Array.prototype.slice.call(A, start, end); }; + Util.shuffleArray = function (a) { + for (var i = a.length - 1; i > 0; i--) { + var j = Math.floor(Math.random() * (i + 1)); + var tmp = a[i]; + a[i] = a[j]; + a[j] = tmp; + } + }; + Util.bake = function (f, args) { if (typeof(args) === 'undefined') { args = []; } if (!Array.isArray(args)) { args = [args]; } diff --git a/www/form/inner.js b/www/form/inner.js index f9427024f..ce6379908 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -1471,6 +1471,7 @@ define([ var map = {}; var invMap = {}; var sorted = false; + Util.shuffleArray(opts.values); var els = opts.values.map(function (data, i) { var uid = Util.uid(); map[uid] = data;