This script will allow respondents to see Choice question options, Grid rows and Grid columns in alphabetical order.
This script will work for the following question types:
- Choice Questions (standard and visual)
- Single/Multi Choice Grid Rows (standard and visual)
- Single/Multi Choice Grid Columns (standard and visual)
- Scale Slider Grids
- Single Choice Card Sorts: rows=cards
- Rank Order Grids
- Rank Order Sorts
- Allocation Grids
- Allocation Sliders
Note:
All supported languages are compatible with this script.
Images are alphabetized based on the image path. E.g. If image is placed in Shared folder, it will be alphabetized based on the Shared/ImageName.jpg file name
Detailed Steps
- Copy the script from below.
- Select the reordering question in the Questionnaire Tree.
- In the Scripting section of the question, click Edit Scripts.
- Paste the script into the On Load tab.
- Change QUESTION_NAME to the name of your question to reorder options.
- Change -1 to precode of the answer options you would like to fix position,. If you do not have any items to fix, leave it as is.
- For example: the 'None of these' exclusive option.
- Separated by a comma if there are multiple items.
- Change false to true if you want to reorder Grid columns.
- Click Save.
- Validate and test your survey.
/* Script Name: How do I show options in alphabetical order? To ensure your script works as expected, always copy the original script from the script library found in the support portal. Failure to use the most up to date script from the script library may cause unexpected results. */ IOrderable question = QUESTION_NAME; int[] fixItems = {-1}; bool isCol = false; /* DO NOT EDIT BELOW */ try { IList Ftemp; GridSequence questionCols = null; ArrayList Otemp = new ArrayList(); ArrayList OtempOrder = new ArrayList(); Comparer cpr = new Comparer( new System.Globalization.CultureInfo( this.Culture ) ); if(isCol) { questionCols = (GridSequence)question; question = questionCols.QuestionTemplate; } if (question is ChoiceQuestion){ // choice question foreach(Answer ans in ((ChoiceQuestion)question).Answers) { Otemp.Add(ans.Html); OtempOrder.Add(ans.OrderInParent+1); } } else if (question is GridSequence){ foreach(ShowQuestionAction sqa in ((GridSequence)question).WorkflowSteps) { if(sqa.ChoiceQuestion != null) { // choice grid Otemp.Add(((ChoiceQuestion)sqa.ChoiceQuestion).Html); } else { // allocation grid Otemp.Add(((VerbatimQuestion)sqa.VerbatimQuestion).Html); } OtempOrder.Add(sqa.OrderInParent+1); } } if(Otemp.Count > 0) { string[] oArry = (string[])Otemp.ToArray(typeof(string)); int[] oArryOrder = (int[])OtempOrder.ToArray(typeof(int)); Array.Sort(oArry, oArryOrder, cpr); if(fixItems.Length >= 1 && fixItems[0] != -1){ ArrayList fixingItems = new ArrayList(oArryOrder); for(int i = 0; i < fixItems.Length; i++){ int temp = (int)fixItems[i]; fixingItems.Remove(temp); fixingItems.Insert(fixItems[i]-1,temp); } oArryOrder = (int[])fixingItems.ToArray(typeof(int)); } if(isCol) ReorderColumns(questionCols, oArryOrder); else ReorderItems(question, oArryOrder); } } catch (Exception e) { if(Testing) NewError(e.ToString()); else throw e; }
Comments
0 comments
Article is closed for comments.