Would love ability to randomly sort the list of available questions in a multiple choice question. Best practice for surveys to avoid people always clicking the first item and it being the same in every case.
Since we can put in an option called “Other” as well, it would be ideal to also have a way to exempt some choices from the random sort.
Note that this can be implemented via our logic feature as well – we allow dynamically updating options, and you can rearrange them in a random order plus exempt certain options from being rearranged as well
Good to know… but Given surveys best practices are to usually randomize order, it would be awesome to also not require advanced logic for this and it be a straightforward option in the UI.
That said, I can try this logic suggestion to get unblocked for now. You could problaby guess that I was going to ask for an example how to do this
My guess is we need to do this using the advanced logic but not sure how. Tee links in your help doc here seem to be broken as it’s pointing to the same section?
is there a way to reference the current field that triggered the rule w/o explicitly specifying the name? I didn’t see it in the field or form properties in the docs. I expected to be able to call something like feathery.fields.getCurrentId() to then get the ID like this:
let currentFieldId = feathery.fields.getCurrentId();
let currentField = feathery.field[currentFieldId];
let currentFieldOptions = currentField.options;
currentField.options = shuffleArray(currentFieldOptions);
this way I could then have as many form steps trigger this… The way documented in help makes it hard to share code across multiple steps, when in this case is super helpful because the randomization is common. It also saves needing to chase updating field names in the javascript if you change field name in the UI–it would just auto follow whatever the current name is.
or am I thinking about this incorrectly and rules are always required to explicitly name the field names/IDs that they are operating on?
btw, the one downside of this is that if you got back and forth between steps, the order keeps changing. Is there some way to only do this randomization the first time a step is loaded and have the options stay in the last order?
I’m trying to figure out why this code doesn’t work. I’m missing something because the shuffleArray function shuffles the entire objects within the array, which means both the value and label properties (and any image property if present) are shuffled together. This maintains the association between the value and label within each option. I’m not sure why image wouldn’t be as well?
// define string to do a substring search on. All fields that match will be randomized
const fieldNameSearch = '1111where_selling_currently';
const excludeLast = true;
// Utility function to randomize array elements, excluding the last if specified
function shuffleArray(array, excludeLast) {
const newArray = [...array];
const limit = excludeLast ? newArray.length - 2 : newArray.length - 1;
for (let i = limit; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[newArray[i], newArray[j]] = [newArray[j], newArray[i]];
}
return newArray;
}
// Find and shuffle options for fields that include the substring in their name
Object.keys(feathery.fields).forEach(key => {
if (key.includes(fieldNameSearch)) {
const field = feathery.fields[key];
if (field.options && Array.isArray(field.options)) {
field.options = shuffleArray(field.options, excludeLast);
}
}
});