Welcome to the LimeSurvey Community Forum

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

Array dual scale with second scale as text input

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 2 months ago #179771 by vzyldd
Limesurvey Version 3.6.1+180406
Template: Fruity

Please help. I need to create a dual scale array with the second scale as a text input. Can the dual scale array be modified or do I need to use another question type?

I have attached the layout needed.

Many thx
Attachments:
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179774 by Joffm
Hi,
yes, indeed, the dual array is not the best choice.

Here an example. It contains three questions, all the same structure.
The third refers to your wishes.





Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 2 months ago #179775 by vzyldd
Hi Joffm,

big thank you. This is perfect. Now the question, how do I do it as in your example. I tried different types but can't find the magic. I need to do this for several of the questions in the survey. Your help is much appreciated.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179776 by Joffm
Hi,
sorry, I do not understand your question.

You see the question type: array(texts)


and in the sozurce code of thee question the javascript which you have to adapt.
Here for the first
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X001', 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>'); 
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Please choose...</option>\
                          <option value="1">Red</option>\
                          <option value="2">Blue</option>\
                          <option value="3">Pink</option>\
                          <option value="3">Purple</option>\
                        </select>');  
    $('.answer-item.answer_cell_X005', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Please choose...</option>\
                          <option value="1">AAA</option>\
                          <option value="2">BBB</option>\
                          <option value="3">Do not know</option>\
                        </select>'); 
    $('.answer-item.answer_cell_X006', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Please choose...</option>\
                          <option value="1">AAA</option>\
                          <option value="2">BBB</option>\
                          <option value="3">Do not know</option>\
                        </select>'); 
 
    // Listeners
    $('.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');
      }
    });
 
    // 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>

and here for the third question:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X001', 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>\
                        </select>'); 
 
    // Listeners
    $('.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');
      }
    });
 
    // 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>

So the only difference are the drop-downs.

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 2 months ago #179778 by vzyldd
Thx Joffm.

I was just uncertain what array format to use. I've tried your solution but I am unable to insert the script in the question. Keep getting an error message (unknown action) when I try to save the question after I inserted the script. I've attached the survey. The problem is Q10a (BRAND NAMES AND PRICES) Am I missing something?

Kind regards
Erik
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179817 by Joffm
Hi,
1. do you really want to display "all on one page"?

Of course, this is not possible.

2. After importing in Q9a were only 11 lines of the script in the source code, not the whole one.

3. In the script you see (and in my screenshot) that the script refers to the Codes:
$('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
and


4. You did not enter the "with-checkbox-array-comments" as a css class.

This is something I found.
Kind regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 2 months ago #179832 by vzyldd
Hi Joffm,

the problem I have is that when the script is inserted in the source of the question, I am unable to save the question. Error message - unknown action. The problem seems to be with the listeners part:

// Listeners
$('.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');
}
});


If I exclude this part from the script the changes to the source in the question saves fine. Unfortunately this part is critical to capture the data. Any ideas?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179839 by Joffm
Hi,
this is strange.
I once could reproduce it.
Try to remove all blanks here.

to


On the other side:
If I try to run your entire survey my LS installation crashes.
So I removed everything except the group "BRAND NAMES AND PRICES"
And it works fine.


Now I will insert all other groups one by one to find out.

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179844 by Joffm
Hi,
as promised I tried to recreate your survey.

But for some reasons I get this error message

Seems to be something with my server.

Well, in the demo playground you find a working example.
You find it in "Ressources / Demo". username ans password are prepunched.


On the other side:
You nearly never use relevance equations or filters. So you have to trust your interviewers and the respondents.
E.g. the "... SPECIFICS" group. You can skip it by entering the relevance equation Q1aTob_2_9=="Y"

Best regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 2 months ago #179859 by vzyldd
Hi,

same type of error I got but only when I inserted the script. I even installed the latest version of Limesurvey on my server with a new database etc but still the same problem. I will adapt the survey layout to use what is possible and not what is nice to have and then try to get to the root of the problem. Something in the script is causing the headaches.

My biggest gratitude to you for all the help and effort you did to try and solve my issue. It is most highly appreciated.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 2 months ago #179861 by Joffm
Hi,
you can see it running correctly in the LS demo installation.

At the moment I am creating the survey with some different question types.

By the way:
Why did you display it "all on one page"?
Is there a special reason?

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 2 months ago #179862 by vzyldd
The client wanted it that way as the area where the survey will roll out has limited wifi/LTE/internet reception and they try to minimize any display/page load errors. Unfortunately here in South Africa some areas still have poor internet and weak reception due to the topography of the country.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose