Adding textbox in basic array

More
3 weeks 5 days ago #170068 by krosser
krosser replied the topic: Adding textbox in basic array
Hi guys,

I need to make an array question with textboxes similar to this



I have a code from Tony to place the textboxes in different columns.
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
		$('#question{QID}').cbArrayComments3({
			column: 3 // Text Input column (-1 will default to last column)
		});
	});
</script>

But when you type in the textboxes, the other radio buttons are automatically unchecked. Usually, it is what you would want, but in my case the comment is for one of the answer columns. So I wonder if it is possible to modify the code to allow the radio buttons be checked while keeping the text?

Many thanks! :)

I'm using the latest LS 3.13 hosted by LS team, not installed locally.
Attachments:

Please Log in or Create an account to join the conversation.

More
3 weeks 4 days ago #170112 by krosser
krosser replied the topic: Adding textbox in basic array
Well, in my case, the change in cbArrayComments worked. :laugh:
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
		$('#question{QID}').cbArrayCommentsgov2q4a({
			column: 3 // Text Input column (-1 will default to last column)
		});
	});
</script>

I'm using the latest LS 3.13 hosted by LS team, not installed locally.

Please Log in or Create an account to join the conversation.

More
3 weeks 4 days ago #170114 by krosser
krosser replied the topic: Adding textbox in basic array
Hey Tony, do you think it is possible to move two multiple short text questions on top an array? Or perhaps an array(texts) to an array? I have to make a multiple choice question with two textbox columns, similar to this:

I'm using the latest LS 3.13 hosted by LS team, not installed locally.
Attachments:

Please Log in or Create an account to join the conversation.

More
3 weeks 3 days ago - 3 weeks 3 days ago #170234 by tpartner
tpartner replied the topic: Adding textbox in basic array
I would be inclined to use an array-texts type question and swap out some of the text inputs for checkbox inputs.

Add a script like this to the question source. The check-boxes will give a value of "Y" in the data when checked.

My time is limited this week so I will leave it to you to test the data and, perhaps, adjust styling.

<script type="text/javascript" charset="utf-8">
 
 
	$(document).on('ready pjax:scriptcomplete',function(){
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Column-specific classes
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('th, td', this).each(function(i) {
				$(this).addClass('column-'+i);
			});
		});
 
		// Insert checkboxes
		$('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3, .answer-item.column-4, .answer-item.column-7, .answer-item.column-8', thisQuestion).addClass('custom-checkbox-item');
		$('.custom-checkbox-item', thisQuestion).each(function(i) {
			var thisID = $('input:text:eq(0)', this).attr('id');
			$('label', this).before('<input class="" id="'+thisID+'" value="Y" type="checkbox" name="'+thisID.replace(/answer/, '')+'" />');
			if($('input:text:eq(0)', this).val() == 'Y') {
				$('input:checkbox:eq(0)', this).prop('checked', true);
			}
			$(this).removeClass('text-item').addClass('checkbox-item');
			$('input:text:eq(0)', this).remove();
		});
 
		// Identify exclusive items
		$('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3, .answer-item.column-4, .answer-item.column-5, .answer-item.column-6', thisQuestion).addClass('non-exclusive-item');
		$('.answer-item.column-7, .answer-item.column-8', thisQuestion).addClass('exclusive-item');
 
		// Listeners for exclusive items
		$('.non-exclusive-item input:checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				$(this).closest('tr.subquestion-list').find('.exclusive-item input:checkbox').prop('checked', false);
			}
		});
		$('.non-exclusive-item input:text', thisQuestion).on('keyup change', function(e) {
			if($.trim($(this).val()) != '') {
				$(this).closest('tr.subquestion-list').find('.exclusive-item input:checkbox').prop('checked', false);
			}
		});
		$('.exclusive-item input:checkbox', thisQuestion).on('change', function(e) {
			if($(this).is(':checked')) {
				var thisItem = $(this).closest('.answer-item');
				$(this).closest('tr.subquestion-list').find('.answer-item').not(thisItem).find('input:checkbox').prop('checked', false);
				$(this).closest('tr.subquestion-list').find('input:text').val('');
			}
		});
    });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...6-21.lss
File Size:23 KB

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

Please Log in or Create an account to join the conversation.

More
3 weeks 2 days ago #170296 by krosser
krosser replied the topic: Adding textbox in basic array
Wow! That is a great idea. :woohoo:
I have tested the code and it works nicely. You help is very much appreciated!

I'm using the latest LS 3.13 hosted by LS team, not installed locally.

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!