Custom widget: Select2

Select2 Widget Third-party libraries: Select2 MIT

                        

    
        Survey.StylesManager.applyTheme("default");
    


var json = {
  "elements": [
    {
      "type": "dropdown",
      "renderAs": "select2",
      "choicesByUrl": {
        "url": "https://restcountries.eu/rest/v2/all"
      },
      "name": "countries",
      "title": "Please select the country you have arrived from:"
    }
  ]
};

window.survey = new Survey.Model(json);


    survey.onComplete.add(function(result) {
        document.querySelector('#surveyResult').textContent =
            "Result JSON:\n" + JSON.stringify(result.data, null, 3);
    });

survey.data = { countries: 'Andorra' };

$("#surveyElement").Survey({ 
    model: survey 
});

;
                    
<!DOCTYPE html>
<html>
<head>
    <title>Select2 Widget, jQuery Survey Library Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/jquery"></script>
<script src="https://surveyjs.azureedge.net/1.1.0/survey.jquery.js"></script>
<link href="https://surveyjs.azureedge.net/1.1.0/survey.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/js/select2.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.4/css/select2.min.css" rel="stylesheet" />
    <script src="https://unpkg.com/surveyjs-widgets/surveyjs-widgets.js"></script>

</head>
<body>
                <div id="surveyElement">
            </div>
    <div id="surveyResult"></div>

<script type="text/javascript" src="./index.js"></script>

</body>
</html>