Welcome, Guest
Username: Password: Remember me

TOPIC: Answer sourcing to question - hide space and get content in "others"

Re: Answer sourcing to question - hide space and get content in "others" 2 years 6 months ago #74382

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
You're welcome :-)

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 6 months ago #74431

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4139
  • Thank you received: 767
  • Karma: 348
This solution sounds good.
Yeah, it's a neat concept so I spent a little time on it.

1) Set up your survey to use JavaScript.

2) Insert a multiple-text question with 3 subquestions for the "Chosen Brand" and the two "Considered Brands" before the array question.

3) Add the following script to the source of the multiple-text question.

The script:
- Hides the multiple-text question
- Moves the multiple-text inputs to the array header cells
- Validates the "Chosen Brand" and "Considered Brand" inputs
- Ensures that all text fields are completed and the "Considered Brands" are - not the same.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function(){
 
		// Some alert messages
		var msg1 = 'That is not one of the chosen brands';
		var msg2 = 'That is not one of the considered brands';
		var msg3 = 'Please fill in all or the array headers.';
		var msg4 = 'The considered brands cannot be the same.';
 
		// An array containing the possible choices from page 1
		var brands = ['C510','K750I','W580I','J230','6600','N95','N97','N8','E7','S2','Note','Galaxy Y','Vaio','Mac','Net Book','Galaxy Tab','I Pad','Akash','Asha','Sensation','Wild Fire','1100','C2'];
 
		// An array containing the selected choices from page 1
		var chosenBrands = [];
		$('.numeric .questiontext li:not(:contains("No answer"))').each(function(i){
			chosenBrands.push($(this).text());
		});
 
		// An array containing all possible choices from page 1 with the selected removed
		var consideredBrands = brands;
		$(chosenBrands).each(function(i){
			var val = this;
			consideredBrands = $.grep(consideredBrands, function(element) { 
				return element != val; 
			});
		});
 
		// Hide the multiple-short-text
		$('.multiple-short-txt').hide();
 
		// Move the text inputs to the array header cells
		$('.multiple-short-txt input.text').each(function(i){
			$('.array-multi-flexi table.question thead th:eq('+i+')').append('<br />').addClass('header'+(i+1));
			$('.array-multi-flexi table.question thead th:eq('+i+')').append($(this));
		});
 
		// A listener to validate the "Chosen Brand" input
		$('.array-multi-flexi table.question thead input.text:eq(0)').change(function(){
			var validVal = 0;
			var inputVal = $(this).val().toLowerCase();
 
			// Loop through the chosenBrands and test the input value
			$(chosenBrands).each(function(i){
				if(inputVal == this.toLowerCase()) { // If a match is found...
					validVal = 1;
				}
			});
 
			// An invalid input
			if(validVal == 0) { 
				$(this).val('');
				alert (msg1);
			}
		});
 
		// A listener to validate the "Considered Brand" inputs
		$('.array-multi-flexi table.question thead input.text:eq(1), .array-multi-flexi table.question thead input.text:eq(2)').change(function(){
			var validVal = 0;
			var inputVal = $(this).val().toLowerCase();
 
			// Loop through the consideredBrands and test the input value
			$(consideredBrands).each(function(i){
				if(inputVal == this.toLowerCase()) { // If a match is found...
					validVal = 1;
				}
			});
 
			// An invalid input
			if(validVal == 0) { 
				$(this).val('');
				alert (msg2);
			}
		});
 
		// Interrupt next/submit function to make sure the array headers are completed
		$('#movenextbtn, #movesubmitbtn').click(function(){
			var emptyField = 0;
			$('.array-multi-flexi input.text').each(function(i){
				if($(this).val() == '') { 
					emptyField = 1;
					$(this).css({'background':'pink'});
				}
				else { 
					$(this).css({'background':''});
				}
			});
			if(emptyField == 1) {
				alert (msg3);
				return false
			}
			if($('.array-multi-flexi .header2 input.text').val().toLowerCase() == $('.array-multi-flexi .header3 input.text').val().toLowerCase()) {
				$('.array-multi-flexi .header2 input.text, .array-multi-flexi .header3 input.text').css({'background':'pink'});
				alert (msg4);
				return false
			}
		});
	});
 
</script>

Note: This script is designed for a group withe a single multiple-short-txt and a single array-multi-flexi question.

Here is a sample survey:

File Attachment:

File Name: modified_array.lss
File Size: 58 KB


And a screenshot:
Capture2_2012-02-14.PNG
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 6 months ago #74434

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
Wow, this looks great.

-> workarounds... :-)

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 6 months ago #74443

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4139
  • Thank you received: 767
  • Karma: 348
-> workarounds...
Yeah, I thought it should go there but what to call it...

:lol:
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 6 months ago #74444

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4139
  • Thank you received: 767
  • Karma: 348
... and it would be even better with the slider workaround - docs.limesurvey.org/Workarounds%3A+Quest...y-Dual-Scale-Numbers
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 6 months ago #74469

  • Newbeedu
  • Newbeedu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
You all are amazing!

The screenshot made my day, or made my week or may be even month. :laugh:

Awaiting to get my server updated to newer built and to see the solution work myself.

I have ran out of words to thank you all! :)
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 6 months ago #74473

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
Newbeedu wrote:
You all are amazing!

The screenshot made my day, or made my week or may be even month. :laugh:

Awaiting to get my server updated to newer built and to see the solution work myself.

I have ran out of words to thank you all! :)
You're welcome :-)

If our hints have been helpful and you enjoy limesurvey please consider a donation to the team .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 5 months ago #75721

  • Newbeedu
  • Newbeedu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
This workaround that has been put in is hiding all the multiple text questions on that page.

I had put another multiple short text question on this page and that does not appear. As that question is mandatory, when I try to submit the survey, it does not allows me to submit neither does it shows where to fill the other question.

I have replaced multiple short text with a non-mandatory 'multiple choice with comments' question form, so that the answers can be put in for each heading.

Is it a bug?

I do not need an immidiate solution, but i am writing this as I wanted to bring this to your notice.

Thanks,
The administrator has disabled public write access.

Re: Answer sourcing to question - hide space and get content in "others" 2 years 5 months ago #75725

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4139
  • Thank you received: 767
  • Karma: 348
That's not a bug. This solution (and most solutions in the forum) is developed and tested for a specific case. If your circumstances are different you may need to modify the solution.

If you have more multiple-short-text questions, change this:
$('.multiple-short-txt').hide();

To this and replace "QQ" with the ID of the multiple-short-text that you want to hide:
$('.questionQQ').hide();
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: Newbeedu

Re: Answer sourcing to question - hide space and get content in "others" 2 years 5 months ago #75730

  • Newbeedu
  • Newbeedu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
I made this change but it is not hiding the question.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.155 seconds
Donation Image