Welcome to the LimeSurvey Community Forum

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

State and City Form

  • UDL123udl
  • UDL123udl's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 3 months ago #246116 by UDL123udl
State and City Form was created by UDL123udl
Please help us help you and fill where relevant:
Your LimeSurvey version:  LimeSurvey Community Edition
Versión 5.1.13+210923
Own server or LimeSurvey hosting:  hayde.deepraven.com/index.php/admin/index
Survey theme/template: Technology for the deaf
==================
Hello, I have been building a survey for deaf people and their techonology habits in Mexico. I am writing a thesis about this and after the survey is finished we want to figure out how many deaf people in Mexico actually use the internet and their devices, In other words, we want to know how much the deaf community involves with IT. So I already have a code here that permits me to choose the state and it will have to use the code for every municipalities. I already have a list of those codes in an excel sheet. The total amount of municipalities I have in my list is 2,430. However, whenever I copy and paste the codes for those cities, the Limesurvey page fails to add those codes for the question.

I get this error that says that my code has a duplicate answer code every time I try to add those municipalities. I hope I made this clear and I hope somebody helps me. I have added a picture of the error in the attached files. If you need the limesurvey file, I have added it too.

[img]C:\Users\Haydeé\Documents\Tesis\error.limesurvey.codigoduplicado.MHT[/img]

 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago - 1 year 3 months ago #246120 by Joffm
Replied by Joffm on topic State and City Form
Hi,
this is really not the best solution.
Here two examples wtih "easy-autocomplete"

1. States and cities in BRAZIL
 


2. A three level approach: region, province, city in Italy
 

Here the main parts of the script (of course, it is not my script; it was created from our javascript guru @tpartner)
Code:
<script src="/upload/surveys/{SID}/files/jquery.easy-autocomplete.js"></script>
<link href="/upload/surveys/{SID}/files/easy-autocomplete.css" rel="stylesheet" />
 
<script type="text/javascript" data-author="Tony Partner">    
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // Identify this question
        var thisQuestion = $('#question{QID}');
 
      
        // Define the data
        var fullData = [
{ 'e': "Acre", 'm': "Acrelândia" },
{ 'e': "Acre", 'm': "Assis Brasil" },
{ 'e': "Acre", 'm': "Brasiléia" },
...
{ 'e': "Alagoas", 'm': "Anadia" },
{ 'e': "Alagoas", 'm': "Arapiraca" },
{ 'e': "Alagoas", 'm': "Atalaia" },
{ 'e': "Alagoas", 'm': "Barra de Santo Antônio" },
{ 'e': "Alagoas", 'm': "Barra de São Miguel" },
...
{ 'e': "Tocantins", 'm': "Tupiratins" },
{ 'e': "Tocantins", 'm': "Wanderlândia" },
{ 'e': "Tocantins", 'm': "Xambioá" },
        ];
 
        // Define some elements and vars
        var keys = ['e', 'm'];
        var input1 = $('.answer-item:eq(0) input:text.form-control', thisQuestion);
        var inputs = {
            0: $('.answer-item:eq(0) input:text.form-control', thisQuestion),
            1: $('.answer-item:eq(1) input:text.form-control', thisQuestion),
        }
        var answers = {
            0: $.trim($(inputs[0]).val()),
            1: $.trim($(inputs[1]).val()),
        }
 
        // Create an array of "region" values
        var regions = ;
        $.each(fullData, function(i, val) {
            if(!regions.includes(val.e)) {
                regions.push(val.e);
            }
        });
 
        // Initiate autocomplete on the first input
        var aOptions1 = {
            data: regions,
            list: {
                maxNumberOfElements: 100,
                match: {
                    enabled: true
                },
                onChooseEvent: function() {
                    //If new selection...
                    if($.trim(inputs[0].val()) != answers[0]) {
                        answers[0] = $.trim(inputs[0].val());
                        // Reset following items
                        $('li.answer-item:gt(0) input:text', thisQuestion).val('').trigger('keyup').easyAutocomplete({ 'data': '' });
 
                        //Initiate autocomplete on next input
                        childAutocomplete(0);
                    }
                }
            }
        };
        inputs[0].easyAutocomplete(aOptions1);
 
        function childAutocomplete(index) {
            if((index+1) < $('li.answer-item', thisQuestion).length) {
                var parentInput = inputs[index];
                var nextInput = inputs[(index+1)];
 
                var key1 = keys[index];
                var key2 = keys[(index+1)];
 
              // Define the new data
                var thisFullData = fullData.filter(function(obj) {
                    return (obj[key1] == $.trim(parentInput.val()));
                });
                var thisData = ;
                $.each(thisFullData, function(i, val) {
                    if(!thisData.includes(val[key2])) {
                        thisData.push(val[key2]);
                    }
                });
 
                //Initiate autocomplete on next input
                var aOptions = {
                    data: thisData,
                    list: {
                        maxNumberOfElements: 100,
                        match: {
                            enabled: true
                        },
                        onChooseEvent: function() {
 
                            //If new selection...
                            if($.trim($(nextInput).val()) != answers[(index+1)]) {
                                answers[(index+1)] = $.trim($(nextInput).val());
                                // Reset following items
                                $('li.answer-item:gt('+index+1+') input:text', thisQuestion).val('').trigger('keyup').easyAutocomplete({ 'data': '' });
 
                                //Initiate autocomplete on next input
                                childAutocomplete(index+1);
                            }
                        }
                    }
                };
                nextInput.easyAutocomplete(aOptions);
            }
        }
 
        // Returning to page
        if($.trim(inputs[0].val()) != '') {
            childAutocomplete(0);
        }
    });
</script>



The sample survey
 

File Attachment:

File Name: limesurvey...4921.lss
File Size:869 KB

and a zip file with the necessary *.js and *.css files
 

File Attachment:

File Name: jquery.eas...8-27.zip
File Size:9 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 3 months ago by Joffm.
The following user(s) said Thank You: sociology

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 3 months ago #246122 by Joffm
Replied by Joffm on topic State and City Form
And to answer this

 However, whenever I copy and paste the codes for those cities, the Limesurvey page fails to add those codes for the question.

Yes, there is a limitation.
Depends on the php setting of "max_input_vars"
With "max_input_vars=10000" I am able to insert about 750 answer options.
With "max_input_vars=5000" I am able to insert only about 500 answer options.

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