How to Enable N/A Option in Ranked Questions as Default

How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
Number of replies: 11
Hello everyone. I am trying to figure out a way to have a specific rating chosen by default for the user but I am having a difficult time finding out how to do this.

Looking at some of the code, I have come across the variable "checkedna" which seems like it might do the trick, but I am not sure how to access it. I do not see it on the settings page.

Does anyone know how to specify a particular radio button as the default so the user does not need to select anything if they do not wish to change their answer?

I have also seen the section in the README that states:

2.34 Added default = blank space for choice_1 in rate question type.

I have tried adding that to my rated question, but it doesn't appear to be working. Any help is greatly appreciated.

Thanks!
Average of ratings: -
In reply to Zachary Baiel

Re: How to Enable N/A Option in Ranked Questions as Default

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hello Zachary,
Which version of moodle and Questionnaire are you using?
Which question type are you talking about? Rate or RAdio buttons or...?
It would be easier to understand your question if you gave a concrete example.
Joseph
In reply to Joseph Rézeau

Re: How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
Sorry Joseph. I am using version 2008060402 of the module and 1.9.3+ 20081105 of Moodle.

I did not notice there was a Rank and Radio button option for questions. My apologies.

For this particular example, I am using a Ranked question and was wondering how I can have a value selected by default since a user must rank each item in order for the question to be submitted.

I just tried a Radio Button question using the default= option, but that didn't work either.

Thank you for your help.
In reply to Zachary Baiel

Re: How to Enable N/A Option in Ranked Questions as Default

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Sorry but I still do not understand what you mean. Please post a real example of a question you would have in your questionnaire. And show which value you would like selected.
Joseph
In reply to Joseph Rézeau

Re: How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
Sorry Joseph. I have attached a screen shot of a question. I would like the N/A column to be the defaulted answer for all of the choices.

Thank you.


Attachment RankedQuestionExample.jpg
In reply to Zachary Baiel

Re: How to Enable N/A Option in Ranked Questions as Default

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Thanks Zachary, now I understand what you want. At the moment it is not possible to make the N/A column choices selected by default. I will think about it and would like to have more questionnaire users' opinion before changing the code to include that as a default option.
Joseph
In reply to Joseph Rézeau

Re: How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
Thank you Joseph. I appreciate it.

I would not want to always make the N/A column the default choice, but to be able to select one of the rankings as the default I think would be beneficial.

I will try looking at the code to see what I can do in the meantime. If you have any suggestions to get this accomplished in the meantime, let me know.

Thank you again!
In reply to Zachary Baiel

Re: How to Enable N/A Option in Ranked Questions as Default

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

> to be able to select one of the rankings as the default I think would be beneficial

Sorry, but I can't see the point of having pre-filled choices (other than N/A) in questionnaires and surveys in general. It doesn't seem ethically correct to "force" choices upon respondents. But you may have very good reasons to do so in your particular context of use.

All the best,

Joseph

In reply to Joseph Rézeau

Re: How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
Understandable. I think the prefilled N/A would be a good option, though.

Please keep us posted on how this develops.

In the meantime, I changed the code to allow N/A to be checked by default in this function:

if ($na) {
if ( (in_array($na, $data->{'q'.$this->id})) ||
((isset($data->$str) && ($data->$str == get_string('notapplicable', 'questionnaire'))) ) ) {
$checked = ' checked="checked"';
} else {
$checked = '';
}
$checked = 'checked="checked"';

I am not sure how to get the in_array....condition to be true, so I just made $checked equal to checked after the if/else statement. It appears to be working.

Thank you again!
In reply to Zachary Baiel

Re: How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
OK. That modification will not work for every case. big grin We found issues with it when a survey allows people to save. When they resume their survey, it moves the selection back over to N/A.

Back to the drawing board.
In reply to Zachary Baiel

Re: How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
Is the variable that tells the form it has the save/resume option turned on, $questionnaire->resume?

I am trying to figure out how to access that variable so I can turn the N/A selection off for those surveys.

Any help would be greatly appreciated. Thanks.
In reply to Zachary Baiel

Re: How to Enable N/A Option in Ranked Questions as Default

by Zachary Baiel -
Here is an update for everyone, just in case you need to do this yourself.

I was able to check the N/A column by default for one survey by adding the following lines of code around line 1199. My changes are in red:

if ($na) {
if ( (in_array($na, $data->{'q'.$this->id})) ||
((isset($data->$str) && ($data->$str == get_string('notapplicable', 'questionnaire'))) ) ) {
$checked = ' checked="checked"';
} else {
$checked = '';
}
//Added for Technology Survey
if ($this->survey_id == 8){
$checked = ' checked="checked"';
}
//End of Addition
echo '<td style="width:40; text-align:center" class="'.$bg.'">';
echo '<input name="'.$str.'" type="radio" value="'.$na.'"'.$checked.' /></td>';
}

You need to have the survey ID in order to enable this. To find out the survey ID, you can look at your URL when you are viewing the survey you want to enable this for:

mod/questionnaire/report.php?instance=8

I was not able to allow saving/resuming of the questionnaire since the system would always select the N/A column once the questionnaire was resumed.

I know this is a rather clumsy and crude hack, but it worked for me.