Cart Buy Licenses Contact Integrate into App Docs Support Login/Register
v 1.9.6
v 1.9.6
Overview Survey Creator Survey Creator V2 Examples Docs Source

Avoid adding duplicated questions

Use onQuestionAdded event to avoid duplicating questions in survey


// register property named 'tag'
    .addProperty("question", {
        name: "tag",
        category: "general"

var creatorOptions = {questionTypes : [ "text" ]};
var creator = new SurveyCreator.SurveyCreator("creatorElement", creatorOptions);
creator.showToolbox = "right";
creator.showPropertyGrid = "right";

// assign 'tag' property to some unique value
        name: "countries",
        isCopied: true,
        iconName: "icon-default",
        title: "All countries",
        json: {
            "type": "dropdown",
            optionsCaption: "Select a country...",
            choicesByUrl: {
                url: ""
            tag: "myItem1"

// Check if existing questions have same tag and cancel add operation
creator.onQuestionAdded.add(function(sender, options) {
    if (options.question.tag) {
        var questions = sender.survey.getAllQuestions();
        for (var i = 0; i < questions.length; i++) {
            if (questions[i] !== options.question && questions[i].tag === options.question.tag) {
<!DOCTYPE html>
<html lang="en">
    <title>Use onQuestionAdded event to avoid duplicating questions in survey, Survey Creator Example</title>

<meta name="viewport" content="width=device-width" />
    <script src=""></script>
    <script src="/DevBuilds/survey-knockout/survey.ko.min.js"></script>
    <script src="" type="text/javascript" charset="utf-8"></script>
    <script src="" type="text/javascript" charset="utf-8"></script>
    <!-- Uncomment to enable Select2
    <script src=""></script>
    <link href="" rel="stylesheet" />
    <script src=""></script>
        <script src="/DevBuilds/survey-creator/survey-creator.min.js"></script>
        <link href="/DevBuilds/survey-creator/survey-creator.min.css" type="text/css" rel="stylesheet" />
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="./index.css">

<div id="surveyContainer">
        <div id="creatorElement"></div>

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


This sample demonstrates how to handle the onQuestionAdded event to avoid adding duplicated questions onto the survey designer surface.