Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Array(texts) - Validate only 1 column

  • jackuars
  • jackuars's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago - 6 years 1 month ago #163387 by jackuars
Array(texts) - Validate only 1 column was created by jackuars
So am trying to validate only a single column of an ArrayTexts question. Is there any way to do it? For instance Years of Experience column should contain only numbers

Last edit: 6 years 1 month ago by jackuars.
The topic has been locked.
More
6 years 1 month ago #163394 by jelo
Replied by jelo on topic Array(texts) - Validate only 1 column
Take a look at the section here:
manual.limesurvey.org/Expression_Manager....27that.27_variables

Attached is an old, modified example from this forum.
Should do the trick.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • jackuars
  • jackuars's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago - 6 years 1 month ago #163399 by jackuars
Replied by jackuars on topic Array(texts) - Validate only 1 column
Thanks for this.

On second thought, I wondered instead of "Years of Experience" I would like to have 2 subquestions From (year) & To (year) which will work as a DatePicker question.

So it should appear like this

Name of the Organization | From (Date) | To(Date) | Designation

This would mean that we've this ArrayText question will have a text box and datepicker too. Is it possible to set-up like this?
Last edit: 6 years 1 month ago by jackuars.
The topic has been locked.
More
6 years 1 month ago - 6 years 1 month ago #163404 by jelo
Replied by jelo on topic Array(texts) - Validate only 1 column
LimeSurvey is not supporting free from questions (mixing questions) out of the box via GUI.

LS 3.X might be a gamechanger cause the templatesystem will allow to create questionsthemes.
manual.limesurvey.org/New_Template_System_in_LS3.x
There are some workarounds for older LS version which mix different questions in a arrayquestion.
But I have never seen a workaround with a date/time picker in an arrayquestion.

Multiple question types in array
manual.limesurvey.org/Workarounds:_Quest...stion_types_in_array

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
Last edit: 6 years 1 month ago by jelo.
The topic has been locked.
  • jackuars
  • jackuars's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 years 1 month ago #164051 by jackuars
Replied by jackuars on topic Array(texts) - Validate only 1 column
Can it be done using javascript? I hope tpartner reads this thread
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago - 6 years 1 month ago #164057 by Joffm
Replied by Joffm on topic Array(texts) - Validate only 1 column
Hi,

yes there is an example. Not exactly your desire, but a start and the important thing, the range.
Instaed of months just insert years.

Do a search for Tony's posts about arrays



Here is the script:
Code:
<script type="text/javascript" charset="utf-8">    
 
  $(document).ready(function(){  
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Assign column-specific classes
    $('table.subquestion-list tr', thisQuestion).each(function(i) { 
      $('> *:gt(0)', this).each(function(i){
        $(this).addClass('column-'+(i+1));
        $(this).attr('data-column', i+1);
      });
    });
 
    // Hide the text inputs in columns 2
    $('.column-2 input[type="text"]', thisQuestion).hide();
 
    // Define the select element (dropdown)
    var select1 = '<select class="inserted-select"> \
              <option value="">-- Bitte, wählen --</option> \
              <option value="Europa">Europa</option> \
              <option value="Afrika">Afrika</option> \
              <option value="Asien">Asien</option> \
              <option value="Amerika">Amerika</option> \
              <option value="Australien">Australien</option> \
            </select>';
 
    // Insert the select elements into column 2
    $('.answer-item.column-2').append(select1);
 
    // Initial dropdown values in column 2 (if the question has already been answered)
    $('.answer-item.column-2 input[type="text"]').each(function(i){
      if($.trim($(this).val()) != '') {
        $(this).closest('td').find('.inserted-select').val($.trim($(this).val()));
      }
    });
 
    // Listener on the dropdowns (insert selected values into hidden text input)
    $('.inserted-select').change(function() {
      var thisInput = $(this).closest('td').find('input[type="text"]');
      $(thisInput).val($(this).val());
      checkconditions($(thisInput).val(), $(thisInput).attr('name'), 'text');
    });
 
 
    // Insert the sliders
    $('.answer-item.column-3 input[type="text"]', thisQuestion).each(function(i) {
      $(this).closest('td').addClass('with-slider');
      var thisValue = $(this).val();
      var thisValueArr = thisValue.split(',');
      var sliderValues = [];
      if(thisValueArr.length > 1) {
        $(thisValueArr).each(function(i) {
          sliderValues.push(Number(this));
        }); 
      }
      else {
        sliderValues = [1, 12];
      }
 
      $(this).bootstrapSlider({
        'min': 1,
        'max': 12,
        'step': 1,
        'range': true,
        'value': sliderValues,
        'tooltip': 'always'
      });
 
      // Initialization stuff
      if(thisValue == '') {
        $(this).val('');
        $(this).closest('td').find('.tooltip').hide();
      }
      else {
        updateCallOut($(this).closest('td'));
      }
    });
 
    // A function to insert months in the slider callout
    function updateCallOut(el) {
      var thisTooltip = $(el).find('.tooltip');
      var thisValueArr = $(el).find('input[type="text"]').val().split(',');
      var months = {
        1: 'Januar', 
        2: 'Februar', 
        3: 'März', 
        4: 'April', 
        5: 'Mai', 
        6: 'Juni', 
        7: 'Juli', 
        8: 'August', 
        9: 'September', 
        10: 'Oktober', 
        11: 'November', 
        12: 'Dezember'
      };
      var startMonth = months[thisValueArr[0]];
      var endMonth = months[thisValueArr[1]];
      var callOutText = startMonth;
      if(startMonth != endMonth) {
        callOutText = startMonth+'-'+endMonth;
      }
      $('.tooltip-inner', thisTooltip).text(callOutText);
      thisTooltip.show().css('margin-left', '-'+(thisTooltip.width()/2)+'px');
    }
 
    // Listener on sliders
    $('td.with-slider .slider').on('mousedown', function(event, ui) {
      updateCallOut($(this).closest('td'));
    });      
    $('td.with-slider input[type="text"]', thisQuestion).on('slide slideStop', function(event, ui) {
      updateCallOut($(this).closest('td'));
      checkconditions($(this).val(), $(this).attr('name'), 'text');
    });
 
    // Listener on resizing (override the bootstrap callout behaviour)
    $(window).resize(function() {
      $('td.with-slider', thisQuestion).each(function(i) {
        if($('input[type="text"]', this).val() != '') {
          updateCallOut(this);
        }
      });
    });
 
    // Some clean-up styles (could be placed in template.css
    $('select', thisQuestion).css({
      'border': '2px solid #dce4ec',
      'padding': '0.7em',
      'border-radius': '4px'
    });
    $('.slider.slider-horizontal', thisQuestion).css({
      'margin': '1.7em auto 1em'
    });
    $('.slider-handle', thisQuestion).css({
      'top': '-4px'
    });
  });
</script>

Regards
Joffm

Slightly adapted:


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 years 1 month ago by Joffm.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #164068 by Joffm
Replied by Joffm on topic Array(texts) - Validate only 1 column
Or do it the easy way:


with question validation:
(is_numeric(self.sq_SQ001_X003)) and (self.sq_SQ001_X003>1990) and
(is_numeric(self.sq_SQ001_X004)) and (self.sq_SQ001_X004<2019)
and... (for all subquestions)

X003 and X004 the third and fourth column.

Regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #164090 by tpartner
Replied by tpartner on topic Array(texts) - Validate only 1 column
I think the example Joffm supplied with the sliders is the most elegant. It requires little or no validation.

In the second example, you would also want to check that the "From" is always before the "To". This would also be the case if we inserted date pickers in those columns.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 1 month ago #180251 by lemmon
Replied by lemmon on topic Array(texts) - Validate only 1 column
Unfortunately this example does not work with 3.x, as is the case with most of the code which can be found in this forum for working with text arrays. This makes it really difficult for people who are starting off with a current version of LS. It would be great to have a topic specifically for 3.x users with examples of. I will start one once I have something working.
The topic has been locked.
More
3 years 9 months ago #200574 by JaimeAvalos
Replied by JaimeAvalos on topic Array(texts) - Validate only 1 column
I have an array of texts with 15 lines and I have to apply a range validation. Is there a way to set conditions like those but using the self.sq_ notation to do all in one shot?

I tried:

((self.sq_3) <= 50) and (self.sq_3) >= 1)) or (is_empty(sq_3))

but it does not work.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months ago #200612 by Joffm
Replied by Joffm on topic Array(texts) - Validate only 1 column
Hi,
even if you correct your errors with your brackets
((self.sq_3) <= 50) and (self.sq_3) >= 1)) or (is_empty(sq_3))

((self.sq_X3<=50) and (self.sq_X3>=1)) or is_empty(self.sq_X3)

I used X3 to avoid a conflict with "SQ003".


((self.sq_X3<=50) and (self.sq_X3>=1)) is expanded to:
((Q1_SQ001_X3, Q1_SQ002_X3, Q1_SQ003_X3 <= 50) and (Q1_SQ001_X3, Q1_SQ002_X3, Q1_SQ003_X3 >= 1)

and
is_empty(self.sq_X3).is expanded to :
is_empty(Q1_SQ001_X3, Q1_SQ002_X3, Q1_SQ003_X3, Q1_SQ004_X3)


Obviously this cannot be validated.



Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
More
2 years 11 months ago #215546 by fmdallafontana
Replied by fmdallafontana on topic Array(texts) - Validate only 1 column
Hi,

I'm having some problems using the <, <=, >, >= operators. Subquestion equation doesn't work for these cases, but it works for the ==.
I'm using version 2.72.3+171020. How can I solve it?

Regards,
Fernando
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose