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
  • cindy16's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months 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:
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #198317 by Joffm
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

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • cindy16
  • cindy16's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months ago #198331 by cindy16
Thank you Joffm! Problem solved.
The topic has been locked.
  • cindy16
  • cindy16's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months 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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months ago #198365 by Joffm
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
...
...



Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 11 months ago by Joffm.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months 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:

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:

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.
Last edit: 3 years 11 months ago by tpartner.
The topic has been locked.
  • cindy16
  • cindy16's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months 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
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago - 3 years 11 months 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
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>

File Attachment:

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


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
Last edit: 3 years 11 months ago by Joffm.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months 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
The topic has been locked.
  • cindy16
  • cindy16's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 11 months 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?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months ago #199955 by tpartner
Code:
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.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 11 months 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
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose