Array Text with one column number only without thousand seperator

More
2 months 2 weeks ago #198310 by cindy16
Hi!

I have a question that I have been trying to solve in the pass few days and I just couldn't get my head around and solve the Problem. I am new to LimeSurvey and don't know any coding language, so please bear with me if I ask for detailed instructions. Thank you in advance,

As mentioned, I have a question with Array Text that have 5 column. I have managed to change the 2nd and 5th column into drop down menu. But I also want the 4th column to be number only and without any thousand seperators, like "," or "."(because it is not universal and our Survey will be conducted in 21 countries. So to prevent reading out thousand as decimals, best is not to let "," or "." be an option). Attached a screenshot of the Survey.


I've read many similar post but couldn't find the right solution for my Problems. I would be much appreciated if you can help me. :)
Attachments:

Please Log in to join the conversation.

LimeSurvey Partners
More
2 months 2 weeks ago #198317 by Joffm
So, you want allow only integer numbers?

You may validate the question with the function "is_int"
https://manual.limesurvey.org/ExpressionScript_-_Presentation#Implemented_functions
(is_int(Q1_SQ001_X004.NAOK) or is_empty(Q1_SQ001_X004)) AND
(is_int(Q1_SQ002_X004.NAOK) or is_empty(Q1_SQ002_X004)) AND
...
for all five rows.

Or you validate by a regular expression like
https://manual.limesurvey.org/Using_regular_expressions
(regexMatch('/^[0-9]{0,}$/',Q1_SQ001_X004) AND
(regexMatch('/^[0-9]{0,}$/',Q1_SQ002_X004) AND
...
for all five rows.

You see I coded the columns (the x-axis) with "X001", "X002",...

Joffm


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

Please Log in to join the conversation.

More
2 months 2 weeks ago #198331 by cindy16
Thank you Joffm! Problem solved.

Please Log in to join the conversation.

More
2 months 2 weeks ago #198336 by cindy16
Hi Joffm, another issue appears:

Please see the screen shot. The question has a condition that only appear when former question is yes or no, but is plant. When the question appears, it is already red right away. Is there any way to fix this?

Thank you again

BR
Cindy
Attachments:

Please Log in to join the conversation.

More
2 months 2 weeks ago - 2 months 2 weeks ago #198365 by Joffm
How did you implement the validation?

You have to implement it in "Logic", not in the "General Options" validation.

You may send the lss export.


Joffm

P.S.

Forgot the NAOK in the second term:
(is_int(Q1_SQ001_X004.NAOK) or is_empty(Q1_SQ001_X004.NAOK)) AND
(is_int(Q1_SQ002_X004.NAOK) or is_empty(Q1_SQ002_X004.NAOK)) AND


Same in the regex-solution
regexMatch('/^[0-9]{0,}$/',Q1_SQ001_X004.NAOK) AND
regexMatch('/^[0-9]{0,}$/',Q1_SQ002_X004.NAOK) AND
...
...




Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 2 months 2 weeks ago by Joffm.

Please Log in to join the conversation.

More
2 months 2 weeks ago - 2 months 2 weeks ago #198392 by tpartner
Here is a post that shows how to dynamically force numerics in an array-texts column - www.limesurvey.org/forum/can-i-do-this-w...question-type#174586

If you also want to prevent periods and commas, change the listener to something like this:

// Listener on column 2 inputs
$('.answer-item.column-2 input:text', thisQuestion).on('keyup change', function(e) {
	var thisValue = $.trim($(this).val());
 
	// Strip out non-numerics characters
	newValue = thisValue.replace(/\D/g,'').replace(/,/g,'').replace(/\./g,'');
	$(this).val(newValue).trigger('change');
});

Sample survey attached:

File Attachment:

File Name: limesurvey...7142.lss
File Size:25 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
Last edit: 2 months 2 weeks ago by tpartner.

Please Log in to join the conversation.

More
1 month 2 weeks ago #199927 by cindy16
Hi Tony, thank you for your Reply. I've looked through the Post your refered to and your attachment. I tried adding your code to mine and also the code in the post. But it didn't work. It might be that I put in the wrong place. Could you please take a look at it? Thank you in Advance.


Cindy
Attachments:

Please Log in to join the conversation.

More
1 month 2 weeks ago - 1 month 2 weeks ago #199933 by Joffm
Hi, Cindy,

add the snippet right after the listener of first column ( the dropdown)
To make it clear I split the entire code into three parts
<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');
			}
		});

Now you enter the listener for the numeric input
		// 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');
			}
});
 

and the rest
		// 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'
		});
	});
 
</script>

File Attachment:

File Name: limesurvey...7142.lss
File Size:24 KB


Joffm

Just saw that the entire code with sample survey was here already.
https://forums.limesurvey.org/forum/can-i-do-this-with-limesurvey/116506-customizing-list-dropdown-question-type#174586


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 1 month 2 weeks ago by Joffm.

Please Log in to join the conversation.

More
1 month 2 weeks ago #199941 by Joffm
Here a sample survey with your initial example.

File Attachment:

File Name: limesurvey...42_I.lss
File Size:25 KB




Joffm


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

Please Log in to join the conversation.

More
1 month 2 weeks ago #199954 by cindy16
I did that but it still doesn't work. I don't know where the Problem lies.

The solution with the validation you gave me earlier worked with "," but it still accept ".". Is there anyway to work around that?

Please Log in to join the conversation.

More
1 month 2 weeks ago #199955 by tpartner
I did that but it still doesn't work. I don't know where the Problem lies.
Do you have any JavaScript errors in the console (F12)?

Can you activate a test survey with only that question and give a link here so we can see what is affecting it?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Please Log in to join the conversation.

More
1 month 2 weeks ago #199963 by Joffm

The solution with the validation you gave me earlier worked with "," but it still accept ".". Is there anyway to work around that?


If you talk about this
regexMatch('/^[0-9]{0,}$/',Q1_SQ001_X004.NAOK)
it does not allow "."

As you might see only numbers [0-9] are allowed. Nothing else.


Anyway:
There is the working javascript solution where there seems to be an issue on your side.

Joffm


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

Please Log in to join the conversation.

More
1 month 2 weeks ago #199974 by cindy16
Unfortunately I am not in the position to activate the Survey, but I did share the question in my last post. Could you use that to locate the issue?

Please Log in to join the conversation.

More
1 month 2 weeks ago #199980 by Joffm
Hi,
In your question export you mix up two different scripts.

For the drop-down you use
$('.answer-item.answer_cell_X002',

and for the numeric input
$('.answer-item.column-4 input:text', thisQuestion).on('keyup change', function(e) {

Once you use the code of the column, and once the number of the column, which is not defined in your script

This would have been the part to define the column numbers.
// Column-specific classes
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('th, td', this).each(function(i) {
				$(this).addClass('column-'+i);
			});
		});

So, please use the provided scripts and - in case it fails - send a lss export and not a lsq nor a lsg export.
Both are language sensitive and do not contain some ipmportant settings of the survey.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: tpartner

Please Log in to join the conversation.

More
1 month 2 weeks ago #200024 by cindy16
I tried the regexMatch solution and it works :) Thank you!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now