Beispiel-Umfrage-Template
Umfrage-Templates teilen sich in die HTML-Eingabe, CSS und Javascript auf.
HTML-Eingabe
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <link rel="stylesheet" type="text/css" href="[CSS-HREF /] " />
- <script src="[JS-SRC /]"></script>
- <title>[SURVEY-HEADLINE /]</title>
- </head>
- <body>
- <div class="container">
- <img class="header-image" src="[SURVEY-IMAGE /]" />
- <div class="pagination">Seite [PAGE-NB /] / [PAGE-COUNT /]</div>
- <h1>[SURVEY-HEADLINE /]</h1>
- [MESSAGE type='incomplete']
- <div class="error">Bitte füllen Sie alle Pflichtfelder aus.</div>
- [/MESSAGE][MESSAGE type='more']
- <div class="error">Es wurden nicht genügend Antworten angehakt.</div>
- [/MESSAGE][MESSAGE type='less']
- <div class="error">Es wurden zu viele Antworten angehakt.</div>
- [/MESSAGE]
- <form action="[ACTION-URL /]" method="post">
- [QUESTIONS]
- [TOP]
- <div class="questions">[/TOP]
- [BETWEEN]
- <div class="spacer"></div>
- [/BETWEEN]
- [BOTTOM]
- </div>
- [/BOTTOM]
- [/QUESTIONS]
- [ACTIONS]
- [TOP]
- <div class="actions">
- <div class="mandatory-hint">* Pflichtfragen</div>
- [/TOP]
- [BETWEEN]<br />[/BETWEEN]
- [BOTTOM]
- </div>
- [/BOTTOM]
- [ACTION type='back']
- <input type="submit" name="btn_back" value="Zurück" class="back" />
- [/ACTION]
- [ACTION type='next']
- <input type="submit" name="btn_submit" value="Weiter" class="more" />
- [/ACTION]
- [ACTION type='finish']
- <input type="submit" name="btn_submit" value="Abschicken" class="finish" />
- [/ACTION]
- [/ACTIONS]
- </form>
- </div>
- </body>
- </html>
Javascript
Javascript für Bewertungs-Element
- var RatingQuestion = function(questionContainer) {
- this.questionId = parseInt(questionContainer.id.split('_').pop(), 10);
- this.ratingOptions = Array.from(
- questionContainer.querySelectorAll('input[type="radio"]')
- ).sort(function (a, b) {
- return parseInt(a.value, 10) - parseInt(b.value, 10);
- });
- };
- RatingQuestion.prototype.setActiveIndex = function(value) {
- var optionsCount = this.ratingOptions.length;
- var ratingValue = parseInt(this.ratingOptions[value].value, 10);
- this.ratingOptions[value].checked = true;
- for (var j = 0; j < optionsCount; ++j) {
- var ratingParent = this.ratingOptions[j].parentElement;
- if (!ratingParent) {
- continue;
- }
- if (j < ratingValue) {
- ratingParent.classList.add('active');
- } else {
- ratingParent.classList.remove('active');
- }
- }
- };
- RatingQuestion.prototype.init = function () {
- this.ratingOptions.forEach(function (option, index) {
- option.parentElement.addEventListener('click', function () {
- this.setActiveIndex(index);
- }.bind(this));
- }.bind(this));
- var currentValue = NaN;
- var ratingRadioList = document.forms[0].elements['data[' + this.questionId + ']'];
- if (ratingRadioList instanceof RadioNodeList) {
- currentValue = parseInt(ratingRadioList.value, 10);
- } else {
- if (ratingRadioList.checked) {
- currentValue = parseInt(ratingRadioList.value, 10);
- }
- }
- if (!isNaN(currentValue)) {
- this.setActiveIndex(currentValue - 1);
- }
- };
- window.addEventListener('load', function () {
- Array.from(document.querySelectorAll('.question.rating')).forEach(function (wrapper) {
- var ratingQuestion = new RatingQuestion(wrapper);
- window.setTimeout(function () {
- ratingQuestion.init();
- }.bind(this), 0);
- });
- });
Editor-Ansicht
Die Ansicht im Editor ist unabhängig vom Quellcode des Umfrage-Templates da die verwendbaren Elemente (HTML-Element und Fragen) vorgegeben sind. Das Beispiel soll lediglich den Aufbau der Umfrage illustrieren.
Vorschau
Darstellung der Umfrage mit den unter "Editor-Ansicht" definierten Fragen.