Customizing List (Dropdown) Question Type

More
3 years 4 months ago #174462 by ititca
Is one able to add a text box to allow for a numerical value to be entered in conjunction with the option they've selected from the dropdown list?

See attached for a visual idea of what I'd like to accomplish.

TIA

Attachments:
The topic has been locked.
More
3 years 4 months ago #174464 by ititca
I did come across Tony's "Multiple Question Types In Array" example survey, which I downloaded and imported as a new survey.

In editing the available question types to just "List (Dropdown)" and "Numerical Input" and re-arranging the order, it doesn't show up as three separate rows (A, B and C).

Now if I could get this tweaked to show as separate rows and implement some other elements (ie: Preventing same dropdown option from being selected for different rows/questions, setting numerical input range between 1 - 60), this very well could suit my needs.

Attachments:
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • Visitor
  • Visitor
3 years 4 months ago #174467 by LouisGac
Replied by LouisGac on topic Customizing List (Dropdown) Question Type
if you're in "all in one" mode, you could create a question group for each pair of {dropdown, numerical entry}, and then create a survey theme that displays those question groups the way you want.
The topic has been locked.
More
3 years 4 months ago #174477 by tpartner
I would not use "Multiple Question Types In Array". That is a very old workaround intended for many different question types.

Here is an example of an array-texts type question with some inserted dropdowns and some inputs restricted to numerics - www.limesurvey.org/forum/search?query=is...artner&childforums=1

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: LouisGac, ititca
The topic has been locked.
More
3 years 4 months ago #174498 by ititca
Thanks for your response and assistance Tony.

I've noticed a few different options showing in the thread you referr to in your reply.

Would this be the most suitable option for me to load and edit?

www.limesurvey.org/forum/can-i-do-this-w...list?start=15#173576

And to suit it to my needs, I can simply delete the question types I don't need and rearrange the questions into the order I'm looking for?
The topic has been locked.
More
3 years 4 months ago #174520 by tpartner
Duh, sorry, I pasted the search URL instead of the correct result. :blush:

Yes, that's the one and you will need to modify it a bit for your needs.

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: ititca
The topic has been locked.
More
3 years 4 months ago - 3 years 4 months ago #174524 by ititca

Duh, sorry, I pasted the search URL instead of the correct result. :blush:


All good Tony, at least I was able to find what you specifically had in mind. :)

Yes, that's the one and you will need to modify it a bit for your needs.


Is this easy to modify, or should I brew a pot of coffee and set aside a few hours this evening to make the modifications? Lol

I'm not the most proficient with JS, but can figure things out if given some pointers and direction with regards to the elements that need to be edited.
Last edit: 3 years 4 months ago by ititca. Reason: Spelling typo.
The topic has been locked.
More
3 years 4 months ago #174526 by tpartner
No, it shouldn't be too hard to do. If you get stuck, attache a small test survey containing the array question and I'll tweak it.

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: ititca
The topic has been locked.
More
3 years 4 months ago #174529 by ititca

No, it shouldn't be too hard to do. If you get stuck, attache a small test survey containing the array question and I'll tweak it.


Sounds good. I'll give it a go and see what happens from there.

Thanks again Tony. :cheer:
The topic has been locked.
More
3 years 4 months ago - 3 years 4 months ago #174535 by ititca
So I managed to import it and had a chance to make changes and play around with it. However, I'm still trying to figure out how to change it so that Column 1 is a Dropdown (List) for each of the 6 rows and Column 2 is a small Numerical Input box for a value from 0 to 60.

Find attached a screen shot and the LSS export I generated as per your previous message

File Attachment:

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



I've also noticed that when I try to copy or edit the Question Group and select Save or Save & Close, it comes back with a HTTP 501 error. I tried with other surveys to make the same modifications and didn't encounter any issue saving/copying.

I did come across a couple warnings, one theme related, when I imported the LSS file as part of creating a new survey. I also captured the error and have it attached.

Attachments:
Last edit: 3 years 4 months ago by ititca. Reason: Warnings, not errors, occurred during import process. Corrections in Column Label descriptions (1 not A; 2 not B).
The topic has been locked.
More
3 years 4 months ago #174548 by tpartner
What LimeSurvey version are you using?

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: ititca
The topic has been locked.
More
3 years 4 months ago - 3 years 4 months ago #174551 by jelo
What version of LimeSurvey is used? Look at the bottom to see the complete version.
Edit:Sorry, forgot the refresh the thread.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Last edit: 3 years 4 months ago by jelo.
The following user(s) said Thank You: ititca
The topic has been locked.
More
3 years 4 months ago #174577 by ititca
3.14.8+180829

I believe the most recent stable version.
The topic has been locked.
More
3 years 4 months ago #174586 by tpartner
I'm not sure why you are seeing errors, I saw none when importing your survey.

This will insert drop-downs into column 1 and numeric inputs with 0-60 allowed in column 2.

<script type="text/javascript" charset="utf-8">
 
	$(document).on('ready pjax:scriptcomplete',function(){
		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 selects into column 1
		if($('.answer-item.column-1 .inserted-select', thisQuestion).length == 0) {
			$('.answer-item.column-1', 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>');
		} 
 
		// Listeners on select elements
		$('.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);
		});
 
		// Listener on column 2 inputs
		$('.answer-item.column-2 input:text', thisQuestion).on('keyup change', function(e) {
			var thisValue = $.trim($(this).val());
 
			// Numerics only
			if($.isNumeric(thisValue) === false) {
 
				// Strip out non-numerics characters
				newValue = thisValue.replace(/\D/g,'');
				$(this).val(newValue).trigger('change');
			}
 
			// Max/min values
			var maxAllowed = 60;
			var minAllowed = 0;
			if (thisValue > maxAllowed) {
				alert('The maximum allowed is '+maxAllowed+'.');
				$(this).val(maxAllowed);
			}
			else if (thisValue < minAllowed) {
				alert('The minimum allowed is '+minAllowed+'.');
				$(this).val(minAllowed);
			}       
		});
 
		// Clean-up styles
		$('select.inserted-select', thisQuestion).css({
			'max-width': '100%'
		});
		$('.with-select input:text', thisQuestion).css({
			'position': 'absolute',
			'left': '-9999em'
		});
	});
</script>

Sample survey attached:

File Attachment:

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

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: ititca
The topic has been locked.
More
3 years 4 months ago #174659 by ititca
Thank you for your assistance Tony. Greatly appreciated. Two additional questions:

If I wanted to set a condition that the same option in the dropdown list can't be selected more than once in a question, how would I make this happen?

Lastly... What's the best way for me to send you a thank-you/funds to have a beer or two on me? :)
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now