Hide/Remove Question Help If Empty

More
4 years 1 week ago #95931 by kobaltz
kobaltz created the topic: Hide/Remove Question Help If Empty
I'm trying to hide the question help if no text was entered. I think that it will overall help the look and feel of the survey.



In my question.pstpl file, I have created an ID for each question helper. I then use javascript to check to see if its contents are empty. If so, then hide the element. However, it's not working. Here is what I have.
<tr><td class="survey-question-help" id=help_{QUESTION_CLASS}>{QUESTIONHELP}</td></tr>

<script>
$(document).ready(function(){
  if($('#help_{QUESTION_CLASS}').val().length == 0){
  $('#help_{QUESTION_CLASS}').hide();
  }
});
</script>

Please Log in to join the conversation.

More
4 years 1 week ago - 4 years 1 week ago #95934 by kobaltz
kobaltz replied the topic: Hide/Remove Question Help If Empty
It is actually working. It just took my page a while to refresh. I suppose loading javascript after a page fully loads could display the boxes there until then. However, now it seems a bit random as to which questions will hide their text. They have unique code names.


<div id="question8545" class="text-short mandatory">
<table class="question-wrapper">
<tbody>
<tr>
<td>
<table cellspacing="0" width="100%">
<tbody>
<tr>
<td class="question-text">
<span class="qnumcode">5 </span>
<span class="asterisk">*</span>
Who is your primary contact with the payroll company?
<br>
<span class="questionhelp"></span>
<span id="vmsg_8545" class="questionhelp hide-tip"></span>
</td>
</tr>
<tr>
<td id="help_text-short" class="survey-question-help"></td>
</tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
<script>
$(document).ready(function(){
if($('#help_text-short').val().length == 0){
$('#help_text-short').hide();
}
});
</script>
Last Edit: 4 years 1 week ago by kobaltz. Reason: t

Please Log in to join the conversation.

More
4 years 1 week ago #95935 by kobaltz
kobaltz replied the topic: Hide/Remove Question Help If Empty
I figured it out. I was using too generic of a code in the ID tag. Instead I referenced it off of the Question Number. I used the .is(':empty') check and it works perfectly now.
<script>
$(document).ready(function(){
  if($('#help_{QUESTION_NUMBER}').is(':empty')){
  $('#help_{QUESTION_NUMBER}').hide();
  }
});
</script>

Please Log in to join the conversation.

More
4 years 1 week ago #95942 by Mazi
Mazi replied the topic: Hide/Remove Question Help If Empty
Thanks for sharing your solution.

Please add this at manual -> workarounds ->JavaScript so it doesn't get lost when old forum posts are deleted.
Thanks!


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
3 years 5 months ago #102804 by MikeConom
MikeConom replied the topic: Hide/Remove Question Help If Empty
kobaltz

its a nice idea to hide empty question.

for me i am looking to find a different solution.

The question help text to be hidden except the button(?).
when i press the hep button(?) then question help text to appear.
Have you a solution for this?

Thanks

Please Log in to join the conversation.

More
3 years 5 months ago #102825 by DenisChenu
DenisChenu replied the topic: Hide/Remove Question Help If Empty
Hi,

I do a push qome day ago in skeleyonquest, maybe you can use same system:

github.com/Shnoulle/skeletonquest/commit...ff02b25346858b1ecR13
{if(!empty(QUESTIONHELP),"<tr><td class='survey-question-help'>".QUESTIONHELP."</td></tr>","")}
Ele you don't need help_{QUESTION_NUMBER} , just use:
$('#question{QID} .survey-question-help').hide();

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
The following user(s) said Thank You: MikeConom

Please Log in to join the conversation.

More
3 years 4 months ago #102856 by MikeConom
MikeConom replied the topic: Hide/Remove Question Help If Empty
Denis

Thanks for your responce

Is it possible in your example to be visible only the

question mark and when i press it to be visible the help text ?
Attachments:

Please Log in to join the conversation.

More
3 years 4 months ago #102921 by DenisChenu
DenisChenu replied the topic: Hide/Remove Question Help If Empty
Not with my example.

Need some js here.

Look at jquery documentation : api.jquery.com/

Denis

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
3 years 4 months ago - 3 years 4 months ago #102925 by tpartner
tpartner replied the topic: Hide/Remove Question Help If Empty
Mike, here is an example of how to toggle the visibility of the help text when the image is clicked (this is for the default template and may need to be modified for other templates).

1) Add this to the end of template.js:
$(document).ready(function(){
 
	// Wrap the help text in a <span> element (excluding the help image)
	$('.survey-question-help').wrapInner('<span class="helpText" />');
	$('.survey-question-help').each(function(i) {
		$('img:eq(0)', this).addClass('helpImage');
		$(this).prepend($('img:eq(0)', this));
	});
 
	// Toggle the visibility of the help text
	$('.helpImage').click(function(event) {
		$(this).parent().find('.helpText').fadeToggle(600);
	});
 
	// Show the help element
	$('.survey-question-help').show();
});

2) Add this to the end of template.css:
.survey-question-help,
.survey-question-help .helpText {
	display: none;
}

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 3 years 4 months ago by tpartner.
The following user(s) said Thank You: MikeConom

Please Log in to join the conversation.

More
3 years 4 months ago - 3 years 4 months ago #103164 by MikeConom
MikeConom replied the topic: Hide/Remove Question Help If Empty
Tony, i am working with limespired and i changed only this

$('.survey-question-help').wrapInner('<span class="helpText" style="display: none;" />');
Last Edit: 3 years 4 months ago by MikeConom.

Please Log in to join the conversation.

More
3 years 4 months ago #103168 by tpartner
tpartner replied the topic: Hide/Remove Question Help If Empty
I prefer to do it with CSS, that way there is no "flash" as the JS hides the element.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now