Question T18108
Visible to All Users

Custom JSON in the question

created a year ago

The question is I would like a custom text area to appear there or anywhere else.

Clipboard-File-1.png

When i input [{ "rule_context": {"my_rule": "my_value"}], that will get picked up in the question as below

"elements": [
    {
     "type": "text",
     "name": "question1",
     "title": "Please provide your full name",
     "defaultValue": "John Doe",
     "clearIfInvisible": "onHidden",
     "textUpdateMode": "onBlur"

"custom": [{ "rule_context": {"my_rule": "my_value"}]
    },

I see an example here https://surveyjs.io/survey-creator/examples/add-properties-to-property-grid/reactjs

Hopefully that is the way to go?

Answers approved by surveyjs Support

created a year ago

Hello Kishore,
You can create a new question type "json" and then register it as a property grid editor.
Here is the example of registering new property grid editor.
Here is the example of creating a new question type.

However, I do not see the point. Why do you want Creator end-user to edit JSON? What is the idea?
I feel you are trying to solve something, but since I don't know your final goal, I do not see a big picture. I am pretty sure, you are going into the wrong direction.

Thank you,
Andrew
SurveyJS Team

    Comments (3)

      Thanks Got it.

      The use case here is that, we have internal triggers that when met, will display popups to the user.
      These are configured on a question level as below.

      JSON
      "rule_context": { "flag_message": "Sorry! We don't currently process xyz for this restricted <X>.", "flag_reason": "Ineligible - Restricted <X>", "apply": "abcdclient.decline_check_for_the_restricted_x" }

      This is a function abcdclient.decline_check_for_the_restricted_x invoked internally when an user answers that question. The rules load data from API and verify as well. Hence its a function.

      For Phase 1, this will be manually input.
      phase1_rule.png

      For Phase 2, the property grid editor will be improved to make it easy for an user to pick the rule.

      Is it possible for an end user to add java script function if need be?

        Hello,
        Thank you for the update. If you wish to enable users to enter custom key value pairs, set a property's type to itemvalues.

        JavaScript
        Survey.Serializer.addProperty("survey", { name: "customSurveyProperty", type: "itemvalues", category: "general", visibleIndex: 0 });

        Clipboard-File-1.png

        Alternatively, you may wish to implement a custom trigger by extending the SurveyTrigger class. A custom trigger will be available within the survey's Conditions | Triggers collection editor.
        Use the Serializer.addClass function to register a custom Trigger object.
        A demo is available in the following help desk thread: Custom trigger seem to need the word "trigger" in the name.

        Let us know if you require further assistance.

          Let me note that SurveyJS Creator requires a commercial developer license. Please clarify whether your account is licensed.

          Thanks