Question Custom Render

Use events to customize survey rendering

                        //Add a property a text property into all questions types and into page
Survey.Serializer.addProperty("question", "popupdescription:text");
Survey.Serializer.addProperty("page", "popupdescription:text");
function showDescription(element) {
    document.getElementById("questionDescriptionText").innerHTML = element.popupdescription;
    $("#questionDescriptionPopup").modal();
}


    
        Survey.StylesManager.applyTheme("orange");
    


var json = { 
    title: "Software developer survey.", 
    pages: [
        { title: "What operating system do you use?", popupdescription:  "Select the operating system you are currently using.",
            questions: [
                {type:"checkbox", name:"opSystem", title: "OS", hasOther: true, isRequired: true, popupdescription:  "If you do not use any of the listed operating system, please select 'others' and type your operating system name.",
                    choices:["Windows", "Linux", "Macintosh OSX"]}
            ]  
        },
        {   title: "What language(s) are you currently using?", popupdescription:  "Select all programming languages you have been using for the last six months.", 
            questions: [
            {type:"checkbox", name:"langs",title:"Please select from the list",popupdescription:  "Select all programming languages you have been using for the last six months.", 
                 colCount: 4, isRequired: true,
                choices:["Javascript", "Java", "Python", "CSS", "PHP", "Ruby", "C++", "C", 
                    "Shell", "C#", "Objective-C", "R", "VimL", "Go", "Perl", "CoffeeScript", 
                    "TeX", "Swift", "Scala", "Emacs Lisp", "Haskell", "Lua", "Clojure", 
                    "Matlab", "Arduino", "Makefile", "Groovy", "Puppet", "Rust", "PowerShell"]
            }
        ]},        
        { title: "Please enter your name and e-mail", popupdescription:  "We will not share this information with any third-party organization.", 
            questions: [ 
            {type: "text", name: "name", title: "Name:", popupdescription:  "Please, type your name as 'Given Name' 'Family Name'."}, 
            {type: "text", name: "email", title: "Your e-mail", popupdescription:  "Please, make sure you do not misspell your e-mail."}]
        }]
};

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.onAfterRenderQuestion.add(function(survey, options){
    //Return if there is no description to show in popup
    if(!options.question.popupdescription) return;
    //Add a button;
    var btn = document.createElement("button");
    btn.type = "button";
    btn.className = "btn btn-info btn-xs";
    btn.innerHTML = "More Info";
    var question = options.question;
    btn.onclick = function() { showDescription(question); }
    var header = options.htmlElement.querySelector("h5");
    var span = document.createElement("span");
    span.innerHTML = "  ";
    header.appendChild(span);
    header.appendChild(btn);
});

survey.onAfterRenderPage.add(function(survey, options){
    //Return if there is no description to show in popup
    if(!options.page.popupdescription) return;
    //Add a button;
    var btn = document.createElement("button");
    btn.type = "button";
    btn.className = "btn btn-info btn-xs";
    btn.innerHTML = "More Info";
    btn.onclick = function() { showDescription(survey.currentPage); }
    var header = options.htmlElement.querySelector("h4");
    var span = document.createElement("span");
    span.innerHTML = "  ";
    header.appendChild(span);
    header.appendChild(btn);
});
function onAngularComponentInit() {
    Survey.SurveyNG.render("surveyElement", { 
        model: survey 
    });
}
var HelloApp =
    ng.core
        .Component({
            selector: 'ng-app',
            template: '<div id="surveyContainer" class="survey-container contentcontainer codecontainer"><div id="surveyElement"></div></div> '})
        .Class({
            constructor: function() {
            },
            ngOnInit: function() {
                onAngularComponentInit();
            }
    });
document.addEventListener('DOMContentLoaded', function() {
    ng.platformBrowserDynamic.bootstrap(HelloApp);
});


                    
<!DOCTYPE html>
<html>
<head>
    <title>Use events to customize survey rendering, Angular2 Survey Library Example</title>


    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/jquery"></script>
    <script src="https://npmcdn.com/zone.js/dist/zone-evergreen"></script>
    <script src="https://npmcdn.com/core-js@2.6.5/client/shim.min.js"></script>
    <script src="https://npmcdn.com/rxjs@5.0.0-beta.6/bundles/Rx.umd.js"></script>
    <script src="https://npmcdn.com/@angular/core@2.0.0-rc.5/bundles/core.umd.js"></script>
    <script src="https://npmcdn.com/@angular/common@2.0.0-rc.5/bundles/common.umd.js"></script>
    <script src="https://npmcdn.com/@angular/compiler@2.0.0-rc.5/bundles/compiler.umd.js"></script>
    <script src="https://npmcdn.com/@angular/platform-browser@2.0.0-rc.5/bundles/platform-browser.umd.js"></script>
    <script src="https://npmcdn.com/@angular/platform-browser-dynamic@2.0.0-rc.5/bundles/platform-browser-dynamic.umd.js"></script>
<script src="https://surveyjs.azureedge.net/1.1.20/survey.angular.js"></script>
<link href="https://surveyjs.azureedge.net/1.1.20/survey.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="./index.css">
<link rel="stylesheet" href="https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <!-- Modal -->
<div id="questionDescriptionPopup" class="modal fade" role="dialog">
    <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <p><div id="questionDescriptionText"></div></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>

    </div>
</div>        <ng-app></ng-app>
    <div id="surveyResult"></div>

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

</body>
</html>