Welcome to the LimeSurvey Community Forum

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

th.answertext - display if empty

  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago - 8 years 8 months ago #132598 by stemate1988
th.answertext - display if empty was created by stemate1988
Subject should be: Display as hidden if empty

Evening,

for 10 point or 5 point array questions if the question text is blank a box is still displayed on the page.
this can be shrunk down in the advanced section to 0 however it would like a lot nicer if it was hidden.

Is there any javascript that could hide all of these elements if they are empty?

Much appreciated
Attachments:
Last edit: 8 years 8 months ago by stemate1988. Reason: error
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132606 by tpartner
Replied by tpartner on topic th.answertext - display if empty
LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #132625 by stemate1988
Replied by stemate1988 on topic th.answertext - display if empty
2.00+
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132648 by tpartner
Replied by tpartner on topic th.answertext - display if empty
1) Add this to the end of template.js (so it can be used for multiple questions):
Code:
function removeAnswerText(qID) {
  // Identify some stuff
  var thisQuestion = $('#question'+qID);
  var thisArray = $('table.questions-list', thisQuestion);
 
  // Only if all row labels are empty
  var labelsWithText = $('th.answertext', thisArray).filter(function(i) {return $.trim($(this).text()) != '';}).length
  if(labelsWithText == 0) {
    // Add a class to the question
    thisQuestion.addClass('without-answertext');
 
    // Remove the first column
    $('.col-answers, thead td:eq(0), th.answertext', thisArray).remove();
 
    //Reset the column widths
    $('col', thisArray).attr('width', 100/$('col', thisArray).length+'%');
  }
}

2) Call the function with this script in the question text of the array:
Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){ 
    removeAnswerText({QID});
    });
</script>

3) Since it appears that you are using the citronade template, add this to the end of template.css:
Code:
.without-answertext table.questions-list thead th:first-child,
.without-answertext table.questions-list tbody td:first-child {
  border-width: 1px 1px 0 1px;
  border-left-color: #D5DBE7;
}
 
.without-answertext table.questions-list tbody td:last-child {
  border-right-color: #D5DBE7;
}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #132650 by stemate1988
Replied by stemate1988 on topic th.answertext - display if empty
Cheers for this, I have put the code in the relevant places however it is coming out as the attached. I have cleared the cache just in case also.
I am using a customised skeletonquest template, not sure if this would affect it.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132662 by tpartner
Replied by tpartner on topic th.answertext - display if empty
Can you activate a test survey and give us a link?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago - 8 years 8 months ago #132663 by stemate1988
Last edit: 8 years 8 months ago by stemate1988.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132664 by holch
Replied by holch on topic th.answertext - display if empty
This doesn't lead to the demo survey, but to the login screen of the demo server.

Which of the surveys on this installation is yours?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #132665 by stemate1988
Replied by stemate1988 on topic th.answertext - display if empty
edited my previous message, should be able to access directly now
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132666 by tpartner
Replied by tpartner on topic th.answertext - display if empty
Hmm...seems that in your LS version there is no <td> element th the <thead>.

Try this as the function in template.js:

Code:
function removeAnswerText(qID) {
  // Identify some stuff
  var thisQuestion = $('#question'+qID);
  var thisArray = $('table.questions-list', thisQuestion);
 
  // Only if all row labels are empty
  var labelsWithText = $('th.answertext', thisArray).filter(function(i) {return $.trim($(this).text()) != '';}).length
  if(labelsWithText == 0) {
    // Add a class to the question
    thisQuestion.addClass('without-answertext');
 
    // Remove the first column
    $('.col-answers, thead tr:eq(0) > *:eq(0), th.answertext', thisArray).remove();
 
    //Reset the column widths
    $('col', thisArray).attr('width', 100/$('col', thisArray).length+'%');
  }
}

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: stemate1988
The topic has been locked.
  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 8 months ago #132668 by stemate1988
Replied by stemate1988 on topic th.answertext - display if empty
That's worked thanks a lot for that, appreciate the help!
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose