- Posts: 14
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array Text with one column number only without thousand seperator
- cindy16
- Topic Author
- Offline
- New Member
Less
More
3 years 11 months ago #198310
by cindy16
Array Text with one column number only without thousand seperator was created 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.
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:
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12927
- Thank you received: 3978
3 years 11 months ago #198317
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array Text with one column number only without thousand seperator
So, you want allow only integer numbers?
You may validate the question with the function "is_int"
manual.limesurvey.org/ExpressionScript_-...mplemented_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
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
You may validate the question with the function "is_int"
manual.limesurvey.org/ExpressionScript_-...mplemented_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
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
The topic has been locked.
- cindy16
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
3 years 11 months ago #198331
by cindy16
Replied by cindy16 on topic Array Text with one column number only without thousand seperator
Thank you Joffm! Problem solved.
The topic has been locked.
- cindy16
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
3 years 11 months ago #198336
by cindy16
Replied by cindy16 on topic Array Text with one column number only without thousand seperator
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12927
- Thank you received: 3978
3 years 11 months ago - 3 years 11 months ago #198365
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array Text with one column number only without thousand seperator
How did you implement the validation?
[strike]You have to implement it in "Logic", not in the "General Options" validation.
You may send the lss export.[/strike]
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
...
...
[strike]You have to implement it in "Logic", not in the "General Options" validation.
You may send the lss export.[/strike]
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: 3 years 11 months ago by Joffm.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
3 years 11 months ago - 3 years 11 months ago #198392
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array Text with one column number only without thousand seperator
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:
Sample survey attached:
If you also want to prevent periods and commas, change the listener to something like this:
Code:
// 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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 3 years 11 months ago by tpartner.
The topic has been locked.
- cindy16
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
3 years 11 months ago #199927
by cindy16
Replied by cindy16 on topic Array Text with one column number only without thousand seperator
Attachments:
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12927
- Thank you received: 3978
3 years 11 months ago - 3 years 11 months ago #199933
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array Text with one column number only without thousand seperator
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
Now you enter the listener for the numeric input
and the rest
Joffm
Just saw that the entire code with sample survey was here already.
forums.limesurvey.org/forum/can-i-do-thi...question-type#174586
add the snippet right after the listener of first column ( the dropdown)
To make it clear I split the entire code into three parts
Code:
<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
Code:
// 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
Code:
// 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>
Joffm
Just saw that the entire code with sample survey was here already.
forums.limesurvey.org/forum/can-i-do-thi...question-type#174586
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 3 years 11 months ago by Joffm.
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12927
- Thank you received: 3978
3 years 11 months ago #199941
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Array Text with one column number only without thousand seperator
Here a sample survey with your initial example.
Joffm
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The topic has been locked.
- cindy16
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
3 years 11 months ago #199954
by cindy16
Replied by cindy16 on topic Array Text with one column number only without thousand seperator
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?
The solution with the validation you gave me earlier worked with "," but it still accept ".". Is there anyway to work around that?
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
3 years 11 months ago #199955
by tpartner
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.
Replied by tpartner on topic Array Text with one column number only without thousand seperator
Code:
I did that but it still doesn't work. I don't know where the Problem lies.
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.
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12927
- Thank you received: 3978
3 years 11 months ago #199963
by Joffm
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
Replied by Joffm on topic Array Text with one column number only without thousand seperator
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
The topic has been locked.