Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

"Multiple options" question with several primary and secundary options

More
10 years 3 months ago - 10 years 3 months ago #120496 by marba
Hi all!

I have been using the workaround for secundary options in "multiple options" question , but it is configurated so as to open all the secundary options whenever a primary option is clicked.
That would work fine if only one of the answers would nest several secundary options, like:

Before clicking:

[]Primary 1
[]Primary 2
[]Primary 3

After clicking:

[]Primary 1
[X]Primary 2
....[]Secundary 2.1
....[]Secundary 2.2
[]Primary 3


For me, because every primary has several secundaries, what happens is that even if I click only one primary 1, all the other secundaries open. Like:

[X]Primary 1 (only this should open)
....[]Secundary 1.1
....[]Secundary 1.2
[]Primary 2
....[]Secundary 2.2
....[]Secundary 2.2
[]Primary 3
....[]Secundary 3.1
....[]Secundary 3.2


I thought that some code in the question itself could instruct the secundaries to remain hidden until the correspondent primary is selected, but my limited skills didn't allow me to solve this yet... :unsure:

Any ideas on how to do it? :)


Thanks a lot!
Last edit: 10 years 3 months ago by marba.
The topic has been locked.
More
10 years 3 months ago #120497 by tpartner
That should not happen. What LimeSurvey version and template?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 3 months ago #120499 by marba
Hi Tony,



Template based on default (just added this workaround on js and changed some css)
Version 2.05+

When I preview the question, that does not happen.
But when I run the whole survey, then it happens that the secondary options open.
I have this question type several times throughout the survey (some are the same question, repeated). And actually, in one of the questions this problem does not happen the first time it appears (later on the survey, the same question opens all the subquestions...).

Still I thought it could be something possible to change in the question itself...
The topic has been locked.
More
10 years 3 months ago #120501 by tpartner
I cannot reproduce that in any browser. Please test with the attached multiple-question survey and template.

File Attachment:

File Name: Demo_Secon...oxes.zip
File Size:90.39 KB


File Attachment:

File Name: limesurvey...1491.lss
File Size:30.64 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
More
10 years 3 months ago #120532 by marba
I works fine with that example.

With my questions, it also works when I run then individually. If I run just one group (where these kind of questions exist), it's also fine. The problem is when I run the whole survey. Then the problem I explained happens.
And that is weird...

Besides the opening of all the secondary options, it's also not possible to close them again by unchecking the box.

Is there anything in conditions and survey flow that can change how these multiple-questions with secondary options work?
The topic has been locked.
More
10 years 3 months ago #120534 by tpartner
No, there is nothing in the survey flow that can change this workaround. There must be a JavaScript conflict in your template or in those groups.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 3 months ago #120550 by marba
Thanks a lot for your input Tony.

I copied the survey and tried the following changes:
- applied the demo-secondary-checkboxes template (to exclude some conflict in my template)
- deleted all the other questions that had Javascript (to exclude conflict with other pieces of js)

What remained:
- a survey with 7 groups
- conditions in a screening question


The problem persists...

Only when I removed the screening question (the survey questions only appear if the participant click "Yes" in that initial question) it started working normally!

But now I don't understand why... And several conditions are necessary throughout the survey.


Any more ideas? I'm quite confused now.

Thanks
The topic has been locked.
More
10 years 3 months ago #120551 by tpartner
Please attach a small test survey.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 3 months ago #120561 by marba
The topic has been locked.
More
10 years 3 months ago #120567 by tpartner
Ah, you failed to mention that you have exclusive options in these questions. The workaround is not designed to handle those. I'll need to give some thought to that.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: marba
The topic has been locked.
More
10 years 3 months ago #120568 by tpartner
Ah, you failed to mention that you have exclusive options in these questions. The workaround is not designed to handle those. I'll need to give some thought to that.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
10 years 3 months ago #120573 by Bigred01
Are the exclusive options changing the display style of the inputs? I have had this happen to me before so instead of just using .hide(), i added a class to the hidden items that had display:none!important on it and removed that class when it was time to show them.
The topic has been locked.
More
10 years 3 months ago #120575 by marba
Of course, I had to be missing something :laugh:

I can also try to put some conditions to hide the other options if certain answers are selected, instead of the exclusive options... Or would that create the same problem?

@Bigred, so you had some options always hidden, and then they would appear in some situations? I need the opposite, to hide if some are selected.
The topic has been locked.
More
10 years 3 months ago #120576 by Bigred01
This would expand only the secondary list under the primary you click like it would do without the exclusive options. I'm pretty sure the exclusive script is changing the display property of the list items and overwriting the .hide(). Adding the class with the property display:none!important ensures that it will be hidden until you want to show it.

In the function, change the .hide() to .addClass('display-none') and .show() to .removeClass('display-none') then at the bottom of your template.css file add .display-none { display:none!important; }.

Now if you want them all to show initially then hide the secondary options of unselected primaries when a selection is made, this function wont work for that.
The following user(s) said Thank You: marba
The topic has been locked.
More
10 years 3 months ago #120613 by marba
Thank you Bigred, that was helpful!

I did those changes in the script and css, and now there is no problem with the opening secondary options :)

Just had to write in css without the /!important/ part, though. A warning sign appeared in the css file about it, and the solution in fact only worked after I removed it.


I think the best part from Limesurvey is this forum. I'm learning loads with you people. thanks



Just in case someone else needs this solution, I write here how it looks like now:



Template.js
Code:
 
// A function to handle "secondary" checkboxes
function secondaryCheckboxes(qID, primaryPosition, secondaryCount) {
    // Identify the elements
  var thisQuestion = $('#question'+qID);
  var primaryRow = $('li.question-item:eq('+(primaryPosition-1)+')', thisQuestion);
  var primaryInput = $('input.checkbox', primaryRow);
  var secondaryRows = primaryRow.nextAll('li.question-item:lt('+(secondaryCount)+')');
  var secondaryInputs = $('input.checkbox', secondaryRows);
 
  // Indent the secondaries
  secondaryRows.css({ 'margin-left':'2.5em' });
 
  // Initial states of the secondary answers
  if (primaryInput.prop('checked') == false ) {
    secondaryRows.addClass('display-none') 
  } 
 
  // A listener on the primary answer to show or hide secondary answers 
  primaryInput.click(function (event) { 
 
    // Hide/show the secondary answers accordingly
    if (!$(this).is(':checked')) {
      secondaryRows.addClass('display-none')        
      secondaryInputs.prop('checked', false);
      secondaryInputs.each(function(i) {
        checkconditions(this.value, this.name, this.type);
      });
    }
    else {
      secondaryRows.removeClass('display-none') 
    }
  });
}



Template.css:
Code:
 
.display-none { 
    display:none; 
}
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose