Cart Buy Licenses Contact Support Login/Register
v 1.8.11
v 1.8.11
Overview Survey Creator Examples Docs Source Download

Custom Adorner

Custom adorner for the startWithNewLine property inplace editing


                        
    
        SurveyCreator.StylesManager.applyTheme("bootstrap");
    

ko.components.register("question-start-with-new-line", {
  viewModel: {
    createViewModel: function(params, componentInfo) {
      var model = {
        selection: ko.observable(params.question.startWithNewLine ? "another" : "same")
      };
      var property = Survey.Serializer.findProperty(
        params.question.getType(),
        "startWithNewLine"
      );
      model.selection.subscribe(function(value) {
        var newValue = (value === "another");
        var options = {
          propertyName: "startWithNewLine",
          obj: params.question,
          value: newValue,
          newValue: null,
          doValidation: false
        };
        params.editor.onValueChangingCallback(options);
        newValue = options.newValue === null ? options.value : options.newValue;
        params.question.startWithNewLine = newValue;
        params.editor.onPropertyValueChanged(property, params.question, newValue);

      });
      return model;
    }
  },
  template: "<select data-bind='value: selection'><option value='another'>default</option><option value='same'>Place On The Same Line</option></select>"
});

var questionStartWithNewLineAdorner = {
  getMarkerClass: function(model) {
    return !model.isPanel ? "question_startWithNewLine" : "";
  },
  getElementName: function(model) { return "mainRoot"; },
  afterRender: function(elements, model, editor) {
    var decoration = document.createElement("div");
    decoration.className = "svda-question-startWithNewLine";
    decoration.innerHTML = "<question-start-with-new-line params='question: model, editor: editor'></question-start-with-new-line>";
    elements[0].appendChild(decoration);
    ko.applyBindings({ model: model, editor: editor }, decoration);
    ko.tasks.runEarly();
    editor.onAdornerRenderedCallback(model, "question-startWithNewLine", decoration);
  }
};

SurveyCreator.registerAdorner("question-startWithNewLine", questionStartWithNewLineAdorner);

        
            var creatorOptions = { };
            var creator = new SurveyCreator.SurveyCreator("creatorElement", creatorOptions);
            creator.showToolbox = "right";
            creator.showPropertyGrid = "right";
            creator.rightContainerActiveItem("toolbox");
        

                    
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Custom adorner for the startWithNewLine property inplace editing, Survey Creator Example</title>

<meta name="viewport" content="width=device-width" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js"></script>
<script src="/DevBuilds/packages/survey-knockout/survey.ko.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.10/ace.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.10/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
    <!-- Uncomment to enable Select2
    <script src="https://unpkg.com/jquery"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
    -->
    <link href="/DevBuilds/build/survey-creator.css" type="text/css" rel="stylesheet" />
    <script src="/DevBuilds/build/survey-creator.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="./index.css">

</head>
<body>
    
<style>
    .svda-question-startWithNewLine {
        position: absolute;
        top: -25px;
        left: 50px;
        width: 80px;
        display: none;
    }

    .svda-question-startWithNewLine select {
        width: 100%;
    }

    .svd_q_selected .svda-question-startWithNewLine {
        display: block;
    }
</style>    <div id="surveyContainer">
        <div id="creatorElement"></div>
    </div>

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

</body>
</html>