Help in framing question

More
1 month 1 week ago #190480 by carolsguerra
Hello! I need help .... Want to know if it is possible to create a matrix style question with answer option COM options already registered in list format and text entries, with the "include one more answer" button option. As an example attached.


I have searched in various corners and have not found a solution. Please help me. Thank you!
Attachments:

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

LimeSurvey Partners
More
1 month 1 week ago #190482 by tpartner
Replied by tpartner on topic Help in framing question
1) Here is a thread that describes how to insert drop-downs into an array-texts type question - www.limesurvey.org/forum/can-i-do-this-w...question-type#174586

2) Here is a workaround for a variable length array (make sure to use the code for LS3) - manual.limesurvey.org/Workarounds:_Manip...ble_Text.29_question

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: carolsguerra

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

More
1 month 1 week ago #190484 by carolsguerra
Hello thanks for the answer but using the question you submitted attached does not work the option to add a new answer.

www.partnersinc.biz/surveys//index.php?s...32&newtest=Y&lang=en this link is exactly what I want to do. However the columns must accept text and list option.

Thanks.

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

More
1 month 1 week ago #190485 by tpartner
Replied by tpartner on topic Help in framing question
Did you have a look at my item 1? That is the workaround to insert check-boxes.

Item 2 is the workaround to add/remove rows.

You will need to incorporate both of those.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
The following user(s) said Thank You: carolsguerra

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

More
1 month 1 week ago #190487 by carolsguerra
view, thank you! but i don't understand programming very well, can i send only the lss or lqs file? this if it's not a lot of work ... or anyway i have to change the code?

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

More
1 month 1 week ago #190490 by Joffm
Replied by Joffm on topic Help in framing question
Here you have a working example. drop-downs and row adding.


File Attachment:

File Name: limesurvey...6257.lss
File Size:27 KB


The javascript is rather easy to understand.
You see the part where the drop-down selects are defined. And that here the codes of the x-axis are "X001", "X002",...
That's the only thing you have to adapt.
<script type="text/javascript" charset="utf-8">
	$(document).on('ready pjax:scriptcomplete',function(){
		var thisQuestion = $('#question{QID}');
 
		// Insert selects
		$('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
													<option value="">Please choose...</option>\
													<option value="1">Yes</option>\
													<option value="2">No</option>\
													<option value="3">Do not know</option>\
												</select>'); 
		$('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
													<option value="">Please choose...</option>\
													<option value="1">Red</option>\
													<option value="2">Blue</option>\
													<option value="3">Pink</option>\
													<option value="3">Purple</option>\
												</select>');  
		$('.answer-item.answer_cell_X005', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
													<option value="">Please choose...</option>\
													<option value="1">AAA</option>\
													<option value="2">BBB</option>\
													<option value="3">Do not know</option>\
												</select>'); 
		$('.answer-item.answer_cell_X006', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
													<option value="">Please choose...</option>\
													<option value="1">AAA</option>\
													<option value="2">BBB</option>\
													<option value="3">Do not know</option>\
												</select>'); 
 
		// Listeners
		$('.inserted-select', thisQuestion).on('change', function(i) {
			if($(this).val() != '') {
				$(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('change');
			}
			else {
				$(this).closest('.answer-item').find('input:text').val('').trigger('change');
			}
		});
 
		// Returning to page
		$('.with-select input:text', thisQuestion).each(function(i) {
			var thisCell = $(this).closest('.answer-item');
			var inputText = $.trim($(this).val());
			var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val();
			$('select.inserted-select', thisCell).val(selectval);
		});
 
		// Clean-up styles
		$('select.inserted-select', thisQuestion).css({
			'max-width': '100%'
		});
		$('.with-select input:text', thisQuestion).css({
			'position': 'absolute',
			'left': '-9999em'
		});
	});
 
$(document).ready(function() {
 
   // A function to add or remove rows of an Array (Multi Flexible)(Text) question
	function varLengthArray(qID) {
 
		if ($('#question'+qID+'').length > 0) {
 
			// The HTML content of the Add/Remove elements - modify as you wish
			var addContent = '[+]';
			var removeContent = '[-]';
 
			// Create the Add and Remove elements & insert them
			var el1 = document.createElement('div');
			el1.setAttribute('id','addButton'+qID);
			document.body.appendChild(el1);
			var el2 = document.createElement('div');
			el2.setAttribute('id','removeButton'+qID);
			document.body.appendChild(el2);
 
			// Move them to after the array
			$( 'div#addButton'+qID ).appendTo($( '#question' + qID + ' table.ls-answers' ).parent());
			$( 'div#removeButton'+qID ).appendTo($( '#question' + qID + ' table.ls-answers' ).parent());
 
			// Insert their HTML
			$( 'div#addButton'+qID ).html( addContent );
			$( 'div#removeButton'+qID ).html( removeContent );
 
			// Style the elements - you can modify here if you wish
			$( 'div#addButton'+qID ).css({
				'margin':'10px 0 0 10px',
				'padding':'1px',
				'text-align':'center',
				'font-weight':'bold',
				'width':'auto',
				'cursor':'pointer',
				'float':'left'
			});
 
			$( 'div#removeButton'+qID ).css({
				'margin':'10px 0 0 10px',
				'padding':'1px',
				'text-align':'center',
				'font-weight':'bold',
				'width':'auto',
				'cursor':'pointer',
				'float':'left'
			});
 
			// Initially hide the Remove element
			$( 'div#removeButton'+qID ).hide();
 
			// Call the functions below when clicked
			$( 'div#addButton'+qID ).click(function (event) {
				addRow(qID);
			});
			$( 'div#removeButton'+qID ).click(function (event) {
				removeRow(qID);
			});
 
			// Function to add a row, also shows the Remove element and hides the
			//Add element if all rows are shown
			function addRow(qID) {
				var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
				var rowCount = $( arrayRow ).size() - 1;
				$( arrayRow + '[name="hidden"]:first' ).attr('name', 'visible').show();
				$( 'div#removeButton'+qID ).show();
				if ( $( arrayRow + ':eq(' + rowCount + ')' ).attr('name') == 'visible' )  {
					$( 'div#addButton'+qID ).hide();
				}
			}
 
			// Function to remove a row, also clears the contents of the removed row,
			// shows the Add element if the last row is hidden and hides the Remove
			// element if only the first row is shown
			function removeRow(qID) {
				var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
				var rowCount = $( arrayRow ).size() - 1;
				$( arrayRow + '[name="visible"]:last input[type="text"]' ).val('');
				$( arrayRow + '[name="visible"]:last' ).attr('name', 'hidden').hide();
				$( 'div#addButton'+qID ).show();
				if ( $( arrayRow + ':eq(1)' ).attr('name') == 'hidden' )  {
					$( 'div#removeButton'+qID ).hide();
				}
			}
 
			// Just some initialization stuff
			var arrayRow = '#question' + qID + ' table.ls-answers tr.subquestion-list';
			var rowCount = '';
 
			// Initially hide all except first row or any rows with populated inputs
			$( arrayRow ).each(function(i) {
				if ( i > 0 ) {
					// We also need to give the hidden rows a name cause IE doesn't
					// recognize jQuery :visible selector consistently
					$( this ).attr('name', 'hidden').hide();
 
					$('input[type=text]', this).each(function(i) {
						if ($(this).attr('value') != '') {
							$(this).parents('tbody:eq(0)').attr('name', 'visible').show();
							$( 'div#removeButton'+qID ).show();
						}
					});
					rowCount = i;
				}
			});
		}
    }
 
	// Call the function with a question ID
	varLengthArray(9129);
});  
 
</script>

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:

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!