Welcome to the LimeSurvey Community Forum

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

Validate multiple values in Array Text

  • tammo
  • tammo's Avatar Topic Author
  • Away
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
2 weeks 6 days ago - 2 weeks 6 days ago #274331 by tammo
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.15.23
Own server or LimeSurvey hosting: Own server
Survey theme/template: Not relevant
==================
I try to validate 2 out of 3 columns in an array (Texts)
I present an array texts that asks per vacation for the destination (text), the year the vacation started (so must be between 2021 and 2026 for this year) and how many days the vacation lasted (between 1 and 100).

I do not know how to set up this validation in the second and third column and how to display an appropriate error message.

Error messages could be:
"Start year not valid, should be between 2021 and 2026" (and when we use this question next year, this should be between 2022 and 2027)
"Number of days not valid, should be between 1 and 100 days" 

File Attachment:

File Name: wishtovali...umns.lss
File Size:32.73 KB


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
Last edit: 2 weeks 6 days ago by tammo.

Please Log in to join the conversation.

More
1 week 2 days ago #274402 by Joffm
Hi, Tammo,
it tokk a long time to find a suitable solution without validating each single cell.
My first idea was that it is sufficient that the minimum of a column is not less than the least allowed value and the maximum of a column not greater.
But I got in trouble to calculate the minimum because of the not displayed rows.

Now here is my solution:
To select the year insert a dropdown where the years are displayed dynamically
Here this part of the script
Code:
...
    var currentTime = new Date();
    // returns the year (four digits)
    var year = currentTime.getFullYear();
 
    // Insert selects
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
              <option value="">...</option>\
            <option value="'+year+'">'+year+'</option>\
            <option value="'+(year-1)+'">'+(year-1)+'</option>\
            <option value="'+(year-2)+'">'+(year-2)+'</option>\
            <option value="'+(year-3)+'">'+(year-3)+'</option>\
            <option value="'+(year-4)+'">'+(year-4)+'</option>\
            <option value="'+(year-5)+'">'+(year-5)+'</option>\
    </select>');  
...

And to validate the length of vacation I use an inputmask
[url] robinherbots.github.io/Inputmask/#/documentation [/url]
with a regular expression as mask
Code:
         $('#question{QID} .answer_cell_X003 input[type="text"]').inputmask({ 
            'regex': '[1-9][0-9]?',
            'placeholder': '_',
            'removeMaskOnSubmit': false,
            'rightAlign': true,
         });


The question is mandatory. So all fields have to be filled.

As a second proposal here the same, but with "dynamic" rows.
 
Because rows are hidden by javascript, you have to validate that a row is filled.
Just by counting the entries. Has to be a multiple of 3.
count(self.NAOK)/3==floor(count(self.NAOK)/3)

Here the lss
 

File Attachment:

File Name: limesurvey...7378.lss
File Size:59.98 KB


Joffm

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

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose