Check out the LimeSurvey source code on GitHub!

Modify array question type?

More
4 years 8 months ago #81023 by piquadrat
Hello Limesurvey community,

is there any chance to add text in the upper left cell in an array question type (see red marked cell in attached picture)?

Thanks
Phil

Attachments:

Please Log in to join the conversation.

More
4 years 8 months ago #81038 by tpartner
Not out-of-the-box, but you can insert the text with JavaScript.

1) Set up your survey to use JavaScript .

2)Add the following script to the source of the array. Replace "QQ" with the array question ID .

The script adds a class to the cell for styling and inserts the text defined by newText.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
		var newtext = 'Some inserted text...';
 
		$('#question'+qID+' table.question thead td').text(newtext).addClass('insertedText');
	});
 
</script>

3) Add something like the following to the end of template.css to style the inserted text.
td.insertedText {
	text-align: right;
	vertical-align: bottom;
	color: red;
}


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: piquadrat

Please Log in to join the conversation.

More
4 years 8 months ago #81042 by piquadrat
Thank you Tony!

Unfortunately your solution seem to exaggerate the job ;)

The script replaces all cells with the same text (see picture below). Any idea how to avoid this?

And do you think it's possible to add html code in the "Some inserted text..." field as well?

Thanks again for your help! Much appreciated!

Attachments:

Please Log in to join the conversation.

More
4 years 8 months ago #81044 by tpartner
I tested with the default template. What template are you using and what question type?

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.

More
4 years 8 months ago #81051 by piquadrat
I use a slighty different template, however, I just doublechecked with the default template, which ends up with the same "error".

I'm using the array question type (translated as "Matrix" in German). However, I use custom answers. These are tables implemented by html code (see picture below).




I assume that there is a crossover conflict.
Attachments:

Please Log in to join the conversation.

More
4 years 8 months ago #81054 by tpartner
Yes, that will cause a problem.

Try this:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
		var newtext = 'Some inserted text...';
 
		$('#question'+qID+' table.question thead > tr > td').text(newtext).addClass('insertedText');
	});
 
</script>

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: piquadrat

Please Log in to join the conversation.

More
4 years 8 months ago #81055 by tpartner
Oh, yeah, and for inserting HTML:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		var qID = QQ;
		var newhtml = '<table><tr><td>Some inserted HTML...</td></tr></table>';
 
		$('#question'+qID+' table.question thead > tr > td').html(newhtml).addClass('insertedText');
	});
 
</script>

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: piquadrat

Please Log in to join the conversation.

More
4 years 8 months ago #81078 by piquadrat
Tony! Thank you so much!

Your solution just works wonderful now!

Your help is much appreciated! :)

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form